I was wondering what I have wrong here, i need a grade entered then a switch statement to display they got a A or B, etc. The program runs but when the grade is entered nothing is displayed.
Who said you needed a switch statement? The values ascribed to each “case” have to be those for the variable in switch(variable). But score doesn’t take the values A, B, C etc. Your syntax on the lines starting “case” is also non-c++.
Use an if ... else if .. chain, if deciding on the basis of score.
You could use a switch, but it would be like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
switch (score)
{
case 100:
std::cout << "\nYou got a perfect score\n";
break;
case 99:
case 98:
case 97:
cout << "\nYou got an A\n";
break;
case 89:
default:
break;
}
You would have sections for every range, (99 - 90, 89 - 80) and so on. But then you would have to take the case statements all the way down to (0)zero.
As lastchance says the if/else becomes a better option.
If you are using GCC as your compiler, you could use (nonstandard extension) case ranges to simplify the code if you are really set on using a switch statment: