# If Statement Question

• 11-06-2008
thekautz
If Statement Question
Hello, I am working on a program to calculate the letter grade for a user once they put in their grade as a decimal.
When I try to use the program, the following messages appear:
Code:

```grade.cpp: In function `int main()': grade.cpp:48: syntax error at end of input```
Here is my program, can anyone find what I am doing wrong?
Code:

```#include <iostream> int main() { double x; cout << "Please Enter Percentage Rounded to the Nearest Hundredth of a Percent: " << endl; cin >> x; if (x >= 93) {cout << "Your Score of " << x << " is an A" << endl;} if (x <= 92.99 && x >= 90) {cout << "Your Score of " << x << " is an A-" << endl;} if (x <= 89.99 && x >= 87) {cout << "Your Score of " << x << " is a B+" << endl;} if (x <= 86.99 && x >= 83) {cout << "Your Score of " << x << " is a B" << endl;} if (x <= 82.99 && x >= 80) {cout << "Your Score of " << x << " is a B-" << endl;} if (x <= 79.99 && x >= 77) {cout << "Your Score of " << x << " is a C+" << endl;} if (x <= 76.99 && x >= 73) {cout << "Your Score of " << x << " is a C" << endl;} if (x <= 72.99 && x >= 70) {cout << "Your Score of " << x << " is a C-" << endl; } if (x <= 69.99 && x >= 67) { cout << "Your Score of " << x << " is a D+" << endl; } if (x <= 66.99 && x >= 63) { cout << "Your Score of " << x << " is a D" << endl; } if (x <= 62.99 && x >= 60) { cout << "Your Score of " << x << " is a D-" << endl; } if (x <= 59.99) { cout << "Your Score of " << x << " is an F" << endl; }```
I sure hope that someone can help me out.
Thank you!
• 11-06-2008
abachler
you are missing the brace that closes int main()
• 11-06-2008
tabstop
Where's your close curly brace to end main()?
• 11-06-2008
Sentral
You don't need braces in if statements if it's just one statement. It'll make your code neater, and you'll reduce the risk of making errors.

You should return 0 too! :O
• 11-06-2008
Elysia
Indentation is your friend in situations like these!
• 11-06-2008
matsp
To make Elysia's point clearer:
Code:

```#include <iostream> int main() {     double x;     cout << "Please Enter Percentage Rounded to the Nearest Hundredth of a Percent: " << endl;     cin >> x;     if (x >= 93)     {         cout << "Your Score of " << x << " is an A" << endl;     }     if (x <= 92.99 && x >= 90)     {         cout << "Your Score of " << x << " is an A-" << endl;     }     if (x <= 89.99 && x >= 87)     {         cout << "Your Score of " << x << " is a B+" << endl;     }     if (x <= 86.99 && x >= 83)     {         cout << "Your Score of " << x << " is a B" << endl;     }     if (x <= 82.99 && x >= 80)     {         cout << "Your Score of " << x << " is a B-" << endl;     }     if (x <= 79.99 && x >= 77)     {         cout << "Your Score of " << x << " is a C+" << endl;     }     if (x <= 76.99 && x >= 73)     {         cout << "Your Score of " << x << " is a C" << endl;     }     if (x <= 72.99 && x >= 70)     {         cout << "Your Score of " << x << " is a C-" << endl;     }     if (x <= 69.99 && x >= 67)     {         cout << "Your Score of " << x << " is a D+" << endl;     }     if (x <= 66.99 && x >= 63)     {         cout << "Your Score of " << x << " is a D" << endl;     }     if (x <= 62.99 && x >= 60)     {         cout << "Your Score of " << x << " is a D-" << endl;     }     if (x <= 59.99)     {         cout << "Your Score of " << x << " is an F" << endl;     }```

[quote = "Sentral"]
You don't need braces in if statements if it's just one statement. It'll make your code neater, and you'll reduce the risk of making errors.
[/quote]
Ehm, yes and no. The coding standard where I work says that you should always use braces, whether they are needed or not. The reason for that is that it's quite easy to have something like this:
Code:

```  if (x)       do_something;```
Code:

```  if (x)       do_something;       some_other;```
forgetting to add the braces around the conditional code, and of course, that goes wrong, because despite indentation, some_other is actually always executed.

Quote:

You should return 0 too! :O
In C++, it's is allowed to omit the return statement if you want to return "SUCCESS".

--
Mats
• 11-06-2008
thekautz
Thank you all so much!
Well, I tried ending with a curly bracket and sure enough, that was it!
Thank you so much everyone, you saved me so much time!