-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathif_statement.cpp
More file actions
36 lines (26 loc) · 811 Bytes
/
if_statement.cpp
File metadata and controls
36 lines (26 loc) · 811 Bytes
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> //std::cin. stc::cout
/*Single-statement if statements
*the if statements here only run one statement, so they
*don't need braces ("{}"). Multi-statement if statements
*look like:
*
if(condition){
//do something...
}
*
*you can always use a multi-statement if statement in place
*of a single-statement if statement, but never the other way
*around.
*/
int main(){
char goAgain;//holds the user input.
std::cout <<"\nI <3 you!\n";
std::cout <<"Would you like me to tell you again? (y/n) ";//prompt
std::cin >>goAgain;
if (goAgain == 'y' || goAgain == 'Y') // yes
return main(); //call main again to start program over
else if(goAgain == 'n' || goAgain == 'N') // no
return 0; //successfull quit
else
std::cout <<"\nYou idiot!!! That wasn't an option!\n";
}