int main()
{
std::string a;
std::cout << "Please enter first name. \n";
std::cin >> a;
std::string b;
std::cout << "Please enter last name. \n";
std::cin >> b;
double c, d, e;
std::cout << "Enter the three test scores. \n";
std::cin >> c;
std::cin >> d;
std::cin >> e;
double sum = c + d + e;
int ave = round(sum / 3);
switch (ave)
{
case 1:
case 2:
case 3:
std::cout << "F";
break;
case 4:
std::cout << "D+";
break;
case 5:
std::cout << "C";
break;
case 6:
std::cout << "C+";
break;
case 7:
std::cout << "B";
break;
case 8:
std::cout << "B+";
break;
case 9:
case 10:
std::cout << "A";
break;
default:
std::cout << "N/A";
}
std::cout << ave;
}
I thought I did the switch right, but I could be wrong. I'm thinking maybe it's because I didn't include static cast earlier when trying to get the average. I wasn't sure where to put static cast without disturbing the round function.
I'm sorry I should've phrased it better. When I run the program and input my three "test scores", and click enter I get back the letter grade. Except I don't quite want it to output it out just yet. I was testing out if when I do std::cout << ave; if it returns the letter grade only. But then I got B7 and was very confused. I want it so when I put std::cout << ave; that instead of 7, it comes out as B or whatever letter grade.
You need to use another variable which would be a char and then in the switch statement instead of cout, write 'variable' = 'A', 'B' etc.
Use a string if you want to store more than one letter.
Then you can print the value of that string to display the grade.
'ave' over here is calculated for the switch statement so it would be an integer, it was never intended to hold the grade.. But it holds the average integer value if you want to display it, but that's all was done with it in this code.. so why were you expecting it to hold the grade?
By the way you can write ave like so (it's more precise): int ave = (int)round((double)sum / 3.0);