1) Rewrite the if-else chain by using a switch statement: if(letterGrade == \'A\
ID: 3624431 • Letter: 1
Question
1) Rewrite the if-else chain by using a switch statement:if(letterGrade == 'A')
cout << "The numerical grade is between 90 and 100 ";
else if (letterGrade == 'B')
cout << "The numerical grade is between 80 and 89.9 ";
else if (letterGrade == 'C')
cout << "The numerical grade is between 70 and 79.9 ";
else if (letterGrade == 'D')
cout << "How are you going to explain this one? ";
else
{
cout << "Of course I had nothing to do with my grade. " ;
cout << "It must have been the professor's fault. ";
}
Explanation / Answer
switch(letterGrade)
{
case 'A':cout << "The numerical grade is between 90 and 100 "; break;
case 'B':cout << "The numerical grade is between 80 and 89.9 ";break;
case 'C':cout << "The numerical grade is between 70 and 79.9 "; break;
case 'D': cout << "How are you going to explain this one? "; break;
default: cout << "Of course I had nothing to do with my grade. " ;
cout << "It must have been the professor's fault. "; break;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.