-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program for counting letter grades with switch.cpp
52 lines (47 loc) · 1.26 KB
/
Program for counting letter grades with switch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
int main() {
char grade;
int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0;
cout << "Enter the letter grades." << endl
<< "Enter the EOF character to end input." << endl;
while ((grade = cin.get()) != EOF) {
switch (grade) {
case 'A':
case 'a':
++aCount;
break;
case 'B':
case 'b':
++bCount;
break;
case 'C':
case 'c':
++cCount;
break;
case 'D':
case 'd':
++dCount;
break;
case 'F':
case 'f':
++fCount;
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout << "Incorrect letter grade entered. Enter a new grade." << endl;
break;
}
}
cout << endl
<< "Totals for each letter grade are:" << endl
<< "A: " << aCount << endl
<< "B: " << bCount << endl
<< "C: " << cCount << endl
<< "D: " << dCount << endl
<< "F: " << fCount << endl;
return 0;
}