Find the errors and correct them // This program uses a switch-case statement to
ID: 3667839 • Letter: F
Question
Find the errors and correct them
// This program uses a switch-case statement to assign a letter grade
// (A, B, C, D or F) to a numeric test score.
#include <iostream>
using namespace std;
void main( )
{
int testScore;
cout << “Enter your test score and I will tell you” << endl;
cout << “the letter grade you earned: “;
cin >> testScore;
switch (testScore)
{
case (testScore < 60.0):
cout << “Your grade is F.” << endl;
break;
case (testScore < 70.0):
cout << “Your grade is D.” << endl;
break;
case (testScore < 80.0):
cout << “Your grade is C.” << endl;
break;
case (testScore < 90.0):
cout << “Your grade is B.” << endl;
break;
case (testScore < 100.0):
cout << “Your grade is A.” << endl;
break;
default:
cout << “The score isn’t valid” << endl;
}
}
Explanation / Answer
Better To use Bellow program
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
int testScore;
char grade;
cout<<" Enter your test score and I will tell you = ";
cin>>testScore;
switch(testScore/10)
{
case 10 : grade='A';
break;
case 9 : grade='A';
break;
case 8 : grade='A';
break;
case 7 : grade='B';
break;
case 6 : grade='C';
break;
case 5 : grade='D';
break;
default : grade='F';
}
cout<<" Your Grade is = "<<grade<<endl;
return 0;
}
Out Put:
Enter your test score and I will tell you = 90
Your Grade is = A
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.