Code will not run

Why won't my code run?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int score1, score2, score3, score4, score5, pass, fail;
cin >> score1 >> score2 >> score3 >> score4 >> score5;

pass = score1 + score2 + score3 + score4 + score5;
fail = score1 + score2 + score3 + score4 + score5;

if (pass >= 350 && <= 500)
	cout << "pass";
	
else
	cout << "fail";
	
return 0;
}


line 13: expected primary expression before <=
Haha, i figured it out. Sorry guys.

Last edited on
need brackets for if statements.
i would add an else if.

1
2
3
4
5
6
if (pass >= 350 && <= 500){
	cout << "pass";
}	
else  if (fail >= 0 && fail < 350){
	cout << "fail";
}
Here is a fix to it. Check comments for changes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int score1, score2, score3, score4, score5, pass, fail;
	cin >> score1 >> score2 >> score3 >> score4 >> score5;

	pass = score1 + score2 + score3 + score4 + score5;
	fail = score1 + score2 + score3 + score4 + score5;

	if (pass >= 350 && pass <= 500) //<-------added pass to <=500
		cout << "pass";

	else if (fail >= 0 && fail < 350)//<---------Made this a else if statment
	cout << "fail";

	return 0;
}


Brackets are a good idea and a good habit to get in, but in this case not required.

Check here for more info:
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Topic archived. No new replies allowed.