"Replace the if-else if-...-else with switch. This step has a little challenge!
Okay, now that's great and all, but I can't figure out how to design a switch statement to accept a range of values- they don't seem to be for that at all dammit but I have to do what he asks. What's killing me is he says replace. I could just make each range output 1, 2, 3, 4, 5. Then tack a switch statement on. But then, I wouldn't have replaced the if...else, only added to it needlessly.
switch(score)
{
case –2147483648:
case –2147483647:
case –2147483646:
//...
case 0:
case 1:
case 2:
//...
case 58:
case 59:
cout << "U" << endl;
break;
case 60:
case 61:
//...
case 69:
cout << "D" << endl;
break;
case 70:
case 71:
//...
case 79:
cout << "C" << endl;
break;
case 80:
case 81:
//...
case 89:
cout << "B" << endl;
break;
default:
cout << "A" << endl;
break;
}
You'll want to write a program to generate all the cases for the else branch. Hopefully your instructor will realize they're in error.
Well, gcc provides an extension for using ranges in switches. Then again, as you have already said yourself that's not what switches are for (well, I personally think that in 99% of all cases in which switches are used it's due to laziness of the programmer rather than an actual need anyways).