By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

If statement error

P: 6
Hello:

I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

Can anyone tell me what is missing?
Thank you


#include <iostream>
using namespace std;



int main ()

{

char grade

cout<<"Enter grade\n";
cin>>grade;

if (grade >90)
cout<<"A";

else

if (grade >80)
cout<<"B";

return 0;

}
Sep 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: 7
Hello:

I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

Can anyone tell me what is missing?
Thank you


#include <iostream>
using namespace std;



int main ()

{

char grade

cout<<"Enter grade\n";
cin>>grade;

if (grade >90)
cout<<"A";

else

if (grade >80)
cout<<"B";

return 0;

}

hey there semi colon after grade
Sep 28 '06 #2

P: 6
hey there semi colon after grade
Thank you for pointing that out to me, but now I finish writing the code out and I able to compile it, only the proble is that when I enter the number it does not give me the letter grade. I pasted the code below, can you see anything wrong here?

#include <iostream>
using namespace std;



int main ()

{

char grade;

cout<<"Enter grade";
cin>>grade;

if (grade >90)
cout<<"A";

else

if (grade >80)
cout<<"B";

else

if (grade >70)
cout<<"C";

else

if (grade >60)
cout<<"D";

else

if (grade >50)
cout<<"F";



return 0;

}
Sep 28 '06 #3

P: 7
Hello:

I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

Can anyone tell me what is missing?
Thank you


#include <iostream>
using namespace std;



int main ()

{

char grade // ** semicolon missing here

cout<<"Enter grade\n";
cin>>grade;

if (grade >90)
cout<<"A";

else

if (grade >80)
cout<<"B";

return 0;

}
char grade // ** semicolon missing here
Sep 28 '06 #4

P: 7
Thank you for pointing that out to me, but now I finish writing the code out and I able to compile it, only the proble is that when I enter the number it does not give me the letter grade. I pasted the code below, can you see anything wrong here?

#include <iostream>
using namespace std;



int main ()

{

char grade;

cout<<"Enter grade";
cin>>grade;

if (grade >90)
cout<<"A";

else

if (grade >80)
cout<<"B";

else

if (grade >70)
cout<<"C";

else

if (grade >60)
cout<<"D";

else

if (grade >50)
cout<<"F";



return 0;

}
system("pause"); // before return 0;

it should work . it just depends on what number you put when you run the program
Sep 28 '06 #5

Banfa
Expert Mod 5K+
P: 8,916
It is always worth having a else clause after and if else if ... even if it only outputs a debug message that you are expecting to get.

If the grade is < 50 this program is not going to output anything.


BTW for those scoring less than 50 was is the grade that is worst than an 'F'?
Sep 28 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.