-
Notifications
You must be signed in to change notification settings - Fork 1
/
go_again.cpp
36 lines (23 loc) · 921 Bytes
/
go_again.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
#include <iostream>
int main(){
char goAgain; // y or n resonse
std::cout <<"\nYou're awesome.\n"
<<"Would you like me to tell you again? (y/n): ";
std::cin >>goAgain;
// remember character constants are contained in single quotes.
// and string constants are in
if (goAgain == 'y' || goAgain == 'Y') // y entered
return main(); // run the program again
else if (goAgain == 'n' || goAgain == 'N') // n entered
return 0; // end the program
// if the user is an idiot (give them more chances)
// try again while not y or n
while (goAgain != 'y' && goAgain != 'Y' && goAgain != 'n' && goAgain != 'N') {
std::cout <<"\nI didn't understand, please try again: ";
std::cin >>goAgain;
if (goAgain == 'y' || goAgain == 'Y') // y entered
return main(); // start over the program
else if (goAgain == 'n' || goAgain == 'N') // n entered
return 0; // end the program
}
}