browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need C / C++ help?

Get answers from our community of C / C++ experts on BYTES! It's free.

If statement error

Newbie
 
Join Date: Sep 2006
Location: Nyc
Posts: 6
#1: Sep 28 '06
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;

}



Newbie
 
Join Date: Sep 2006
Location: south africa
Posts: 7
#2: Sep 28 '06

re: If statement error


Quote:

Originally Posted by confusedandinsane

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
Newbie
 
Join Date: Sep 2006
Location: Nyc
Posts: 6
#3: Sep 28 '06

re: If statement error


Quote:

Originally Posted by vandalous

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;

}
Newbie
 
Join Date: Sep 2006
Location: south africa
Posts: 7
#4: Sep 28 '06

re: If statement error


Quote:

Originally Posted by confusedandinsane

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
Newbie
 
Join Date: Sep 2006
Location: south africa
Posts: 7
#5: Sep 28 '06

re: If statement error


Quote:

Originally Posted by confusedandinsane

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
Banfa's Avatar
Administrator
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,633
#6: Sep 28 '06

re: If statement error


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'?
Reply