### What am I doing wrong ?

Write a program that allows the user to enter the grade scored in a programming class (0-100).
If the user scored a 100 then notify the user that they got a perfect score.

★ Modify the program so that if the user scored a 90-100 it informs the user that they scored an A

★★ Modify the program so that it will notify the user of their letter grade
0-59 F 60-69 D 70-79 C 80-89 B 90-100 A

Can someone tell me how can I enter a number and that number will tell which grade I have. For example I wanna type 55 and when I typed it I want that the program to tell me F. How can I do that ?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` `````` #include using namespace std; int main() { int x; cout << "What grade did you scored in the programming class: " <> x; switch (x) { case 1: cout << " F " ; break; case 2: cout << " D " ; break; case 3: cout << " C " ; break; case 4: cout << " B "; break; case 5: cout << " A " ; break; } if ( x == 100 ) { cout << "Perfect score!" <
You cand do a if else chain like that:
 ``1234567891011121314`` `````` if (x < 60) std::cout << 'F'; else if (x < 70) std::cout << 'D'; else if (x < 80) std::cout << 'C'; else if (x < 90) std::cout << 'B'; else { std::cout << 'a' << std::endl; if (x == 100) std::cout << "perfect score"; } std::cout << std::endl;``````

Last edited on
Hi there,

You won't be able to use a switch-statement anymore, because that only checks for equality. What you need to check is whether a number is in between a range of numbers, so if/else if statements will serve that purpose. Note that '&&' is the operator for logical AND, meaning both conditions need to be true:

 ``1234567`` ``````if (x >= 0 && x < 60) std::cout << " F "; else if (x >= 60 && x < 70) std::cout << " D "; //etc. ``````

Hope that helps.

All the best,
NwN
I didnt know how to do that NwN .. you helped me a lot ..
Thx very much !!!
Topic archived. No new replies allowed.