CS101
CS101
false true
grade >= 60
std::cout.precision(5); fixed:
3.14159
std::cout << "default:\n"; 2006.00000
std::cout << a << '\n' << b << '\n' << c << '\n'; 0.00000
true
case a action(s) break
case a
false
true
case b case b action(s) break
false
.
.
.
true
case z case z action(s) break
false
default action(s)
1// Fig. 2.22: fig02_22.cpp
3#include <iostream>
5using std::cout;
6using std::cin;
7using std::endl;
9int main()
10 {
17
20
22
23 switch ( grade ) {
Notice how the case statement is
// switch nested in while
24 used
25 case 'A': // grade was uppercase A
27 ++aCount;
29
32 ++bCount;
33 break;
34
35 case 'C': // grade was uppercase C
37 ++cCount;
38 break;
39
47 ++fCount;
48 break;
49
54
58 break; // optional
59 }
60 }
61
68
69 return 0;
70 }
Enter the letter grades.
Enter the EOF character to end input.
a
B
c
C
A
d
f
C
E
Incorrect letter grade entered. Enter a new grade.
D
A
b
Totals for each letter grade are:
A: 3
B: 2
C: 3
D: 2
F: 1
References
Dietal and Dietal : How to Program C++
3rd Edition