Advertisement
bhok

If Statements

Jun 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     // Here is our first if statements
  6.     // Let's see how it works
  7.     // Try typing in the code below
  8.     // What do you think will happen?
  9.     // Do you see the differences in the code below? Explain what do you see
  10.  
  11.     // Code Section 1
  12.     int pancakes = 5;
  13.  
  14.     if (pancakes > 4)
  15.         std::cout << "We need to eat more pancakes! \n" ;
  16.  
  17.     // ***If needed, include and delete system pause on where needed
  18.     // system("pause");
  19.  
  20.     // Code Section 2
  21.     // Now copy the code below try an if...else statement
  22.     // Now, what if we change the 5 to a 2?
  23.     // What happens if we remove the {} for the second expression?
  24.  
  25.     int pancakesArea2 = 5;
  26.  
  27.     if (pancakesArea2 > 4)
  28.         std::cout << "We need to eat more pancakes! \n";
  29.  
  30.     if (pancakesArea2 < 3)
  31.     {
  32.         std::cout << "WHOA! WE NEED MORE PANCAKES! START THE ENGINES! \n";
  33.     }
  34.  
  35.     // Code Section 3
  36.     // What happens if we included an else statement. What do you think will happen?
  37.  
  38.     int pancakesPies = 5;
  39.  
  40.     if (pancakesPies > 4)
  41.         std::cout << "We need to eat more pancakes!";
  42.  
  43.     else
  44.     {
  45.         std::cout << "WHOA! WE NEED MORE PANCAKES! START THE ENGINES!";
  46.     }
  47.  
  48.     // Code Section 4
  49.    
  50.     // Try changing the numbers and getting all three responses
  51.  
  52.     int pancakesMonsters = 5;
  53.  
  54.     if (pancakesMonsters >= 4)
  55.         std::cout << "We need to eat more pancakes!";
  56.  
  57.     else if (pancakesMonsters == 10)
  58.         std::cout << "WHOA! WE NEED MORE PANCAKES! START THE ENGINES!";
  59.    
  60.     else
  61.         std::cout << "What just happened?";
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement