You are divided by 10.0, which is double, and this will not compile. This should be changed to 10. In addition, you must precede the switch command with an if statement, which checks if it is in the valid range.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int testScore;
cout <<"Enter your test score and I will tell you \n";
cout <<"the letter grade you earned \n";
cin >> testScore;
if (testScore<=100 && testScore>=0)
switch(testScore/10)
{
case 10:
case 9:
cout <<"Your grade is A.\n";
break;
case 8:
cout <<"Your grade is B.\n";
break;
case 7:
cout <<"Your grade is C.\n";
break;
case 6:
cout << "Your grade is D.\n";
break;
case 5:
cout << "Your grade is F.\n";
break;
default:
cout << "That score isn’t valid\n";
}
else
cout <<"That score isn't valid\n";
return 0;
}
source
share