Hi, I am trying to write a program that assigns a number grade (0-100) to a corresponding letter grade. The challenge is that I cannot use nested ifs , else if etc. I can use one (if/else), if it is possible.
For example: 0-59 = F
60-69 = D
70-79 = C
80-89 = B
90 100 = A
If I get a grade that is < 0 or > 100, the user gets one more chance.
I have written most of the code, and it looks something like this:
The challenge is that I cannot use nested ifs , else if etc.
Can you use a switch statement?
1 2 3 4 5 6 7 8 9 10 11 12 13
switch (number_grade/10) // integer division will give us a number from 0 - 10
case 10: letter = 'A';
case 8: letter = 'B';
case 7: letter = 'C';
case 6: letter = 'D';
default: letter = 'F';
Thanks for the replies all. Unfortunately, my professor will not allow switch or nested ifs. It would seem the program would be much easier to write if I was allowed to use them.
The reason I asked for another input in line 20 std:: >> number_grade is because I have to give the user another chance if the grade is not in range. I can take it out but if I do the user will just get a prompt to enter again but will not be able to actually do it unless they start the program over.