Write an application that ask the user for a letter grade A, B, C, D, E, or Q to quit. When the user types the user Q the program must end. Display the following using the information on the table below. Use a switch statement for the selection. When the loop terminates display how many A, B, C, D, or E were entered.
Grade Message
A Excellent
B Very Good
C Good
D Fair
E Poor
#include <iostream>
using namespace std;
int main()
{
cout<<"\nEnter grades (A,B,C,D,E) or Q to quit:\n";
char c;
int count_A=0;
int count_B=0;
int count_C=0;
int count_D=0;
int count_E=0;
while(true){
cin>>c;
if(c=='Q')
break;
switch(c){
case 'A':
cout<<"\nExcellent\n";
count_A++;
break;
case 'B':
cout<<"\nVery Good\n";
count_B++;
break;
case 'C':
cout<<"\nGood\n";
count_C++;
break;
case 'D':
cout<<"\nFair\n";
count_D++;
break;
case 'E':
cout<<"\nPoor\n";
count_E++;
break;
}
}
cout<<"\nA was entered "<<count_A<<" times";
cout<<"\nB was entered "<<count_B<<" times";
cout<<"\nC was entered "<<count_C<<" times";
cout<<"\nD was entered "<<count_D<<" times";
cout<<"\nE was entered "<<count_E<<" times";
return 0;
}
Comments
Leave a comment