C++ problem....Please help?!

Hi all!

I am writing a program. This program is a very small program which finds out the grade someone got.

if someone got 0 - 50, they fail.
if someone got 50-60, they receive a C.
if someone got 60-79, they receive a B.
if someone got 80-100, they receive an A.


This is my code:

#include <iostream>
int main(int argc, char *argv[]) {
float marks;
cout<<"What is your percentage? And if your percentage is a whole number, then write it as a decimal, i.e. 50.0.";
cin>> marks;
if (marks >= 50)
{
cout<<"You have failed the examination";
}
else
{
if (marks >= 60)
{
cout<<"You have recieved a grade of C";
}
else
{
if (marks >= 79)
{
cout<<"You have recieved a grade of B";
}
else
{
cout<<"You have recieved a grade of A";
}
}
}
return 0;
}







for some reason it is showing a syntax error. Please help!!!!!!!
Hi ShehabKKhan,

either add:

using namespace std;

or use
std::cin instead of cin
and
std::cout instead of cout.

With this it compiled.

On the logic: every value above 50 makes your program "you have failed".
Better check for the upper limits, start with:
if (marks <= 50)
{
std::cout<<"You have failed ...";
}
else
{
if (marks <= 60)
{
...

HTH, Holger alias (the) InternetSmurf.
Last edited on
Topic archived. No new replies allowed.