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.
#include <iostream>
using namespace std;
int main()
{
cout << "Please, enter symbols A,B,C,D,E for counting and 'Q' to quit\n";
int countA = 0;
int countB = 0;
int countC = 0;
int countD = 0;
int countE = 0;
char c;
while(cin>>c&&c!='Q')
{
switch (c)
{
case 'A':
countA++;
break;
case 'B':
countB++;
break;
case 'C':
countC++;
break;
case 'D':
countD++;
break;
case 'E':
countE++;
break;
}
}
cout << "\nYou entered:\nA: " << countA
<< "\nB: " << countB << "\nC: " << countC
<< "\nD: " << countD << "\nE: " << countE;
}
Comments
Leave a comment