-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
33 lines (27 loc) · 822 Bytes
/
1.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
/* This program:
1. Accepts input until a $ is typed.
2. Counts the number of periods(.).
3. Reports the number of periods when the program terminates. */
#include <iostream>
int main(void) {
char input = ' ';
int count = 0;
std::cout << "Enter your input: " << std::endl;
while (std::cin >> input) {
if (input == '$') {
std::cout << "This program ends here." << std::endl;
break;
}
switch (input) {
case '.': {
count++;
std::cout << '.' << std::endl;
break;
}
default:
std::cout << input << std::endl;
}
}
std::cout << "You have entered " << count << " periods." << std::endl;
return 0;
}