Sorry, That way of using the case is for ST, I got confused, in C/C++ if you want to use a kind of range you would need to define every case, for example
// and so on until 59
grade = 'F';break ;
// then do the same for 60-69
here is an example
case 'A' :
cout << "Excellent!" << endl;
case 'B' :
case 'C' :
cout << "Well done" << endl;
case 'D' :
cout << "You passed" << endl;
case 'F' :
cout << "Better try again" << endl;
If you don't type a break; after a case and you state another case, both cases will do the same action, as you can see in case 'B' and case 'C', both will output "Well done" because there is no break after case 'B'.
So the best option is using the if statement as some users told you before
the difference between using if and case is that in if each 'if' will be evaluated one by one, in the case, all the cases are evaluated at the same time, I mean, if you are using "if else if" your code first will evaluate if the first condition is true, then the second, third, and so on, if you use case it will execute the corresponding line so the "switch" statement is faster than "if else if"
the difference between using if and case is that in if each 'if' will be evaluated one by one, in the case, all the cases are evaluated at the same time
Please explain. The switch has a haphazard list of constants that it has to compare the integral value against. These are obviously simpler tests for equality than what the if-clauses might contain. However, the if..else if does not need to evaluate any further than to the first true.
The use of score/10 maps range 60-69 into value 6 due to the nature of integer division.