Rewrite the following if-else chain using a switch statement: //Variable Declara
ID: 3558175 • Letter: R
Question
Rewrite the following if-else chain using a switch statement:
//Variable Declaration/Initialization
char letGrad = 'B';
if (letGrad == 'A')
cout << "The numerical grade is between 90 and 100" << endl;
else if (letGrad == 'B')
cout << "The numerical grade is between 80 and 89.95" << endl;
else if (letGrad == 'C')
cout << "The numerical grade is between 70 and 79.95" << endl;
else if (letGrad == 'D')
cout << "The numerical grade is between 60 and 69.95" << endl;
else cout << "F is grade" << endl;
Explanation / Answer
char letGrad='B';
switch(letGrad)
{
case 'A':
cout << "The numerical grade is between 90 and 100"
break;
case 'B':
cout << "The numerical grade is between 80 and 89.95"
break;
case 'C':
cout << "The numerical grade is between 70 and 79.95"
break;
case 'D':
cout << "The numerical grade is between 60 and 69.95"
break;
default:
cout << "F is grade"
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.