Advertisement
Vlad_Cursaru

C++ Tutorial E02 Final Code

Jan 25th, 2021
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     /* 0. PREPREQUISITES: Comparison Operators
  8.         Greater than:       >
  9.         Less than:          <
  10.         Greater or equal:   >=
  11.         Less or equal:      <=
  12.         Equal:              ==
  13.         Not equal:          !=
  14.     */
  15.  
  16.  
  17.     /* 1. Basic structure:
  18.    
  19.         if ( condition ) {
  20.             [lines of code to execute if true];
  21.         }
  22.    
  23.     */
  24.  
  25.     cout << "How old are you? \n";
  26.     int age;
  27.     cin >> age;
  28.  
  29.     if (age >= 18) {
  30.         cout << "Please come in!\n";
  31.     }
  32.     cout << "Exiting...\n";
  33.  
  34.  
  35.     // 2. Else statements
  36.     /*
  37.    
  38.         if ( condition ) {
  39.             [lines of code to execute if true];
  40.         }
  41.         else {
  42.             [lines of code to execute if false];
  43.         }
  44.    
  45.     */
  46.  
  47.     if (age >= 18) {
  48.         cout << "Please come in!\n";
  49.     }
  50.     else {
  51.         cout << "You are not old enough!\n";
  52.     }
  53.  
  54.  
  55.     // 3. Else if statements
  56.     /*
  57.    
  58.         if ( condition ) {
  59.             [ lines of code to execute if true ];
  60.         }
  61.         else if ( condition2 ) {
  62.             [ lines of code to execute if condition2 is true ];
  63.         }
  64.         else {
  65.             [ lines of code to execute if all conditions are false];
  66.         }
  67.    
  68.     */
  69.  
  70.    
  71.     if (age < 18) {
  72.         cout << "You are not old enough!\n";
  73.     }
  74.     else if (age > 30) {
  75.         cout << "You are not young enough!\n";
  76.     }
  77.     else {
  78.         cout << "Please come in!\n";
  79.     }
  80.  
  81.  
  82.     // 4. One-statement ifs
  83.     if (age < 18)
  84.         cout << "You are not old enough!\n";
  85.     else if (age > 30)
  86.         cout << "You are not young enough!\n";
  87.     else
  88.         cout << "Please come in!\n";
  89.    
  90.  
  91.  
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement