473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

If statement error

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
5 2114
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
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
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
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
9,065 Expert Mod 8TB
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

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

Similar topics

1
by: Jay | last post by:
G'day all This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user...
3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
1
by: Jack | last post by:
Hi, I got a asp page where I am getting the following error. (Line 126 is actually the RS.open statement.) ERROR MESSAGE Technical Information (for support personnel) Error Type:
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
8
by: Guybrush Threepwood | last post by:
This is a simplified example of a problem I'm having: typedef struct node { int a; int b; } NODE; Somewhere in my code following lines can be found: switch(op) {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.