Advertisement
bhok

Week 2

Jan 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. //----------------------------------
  2. // Week 2 : If and Else Statements
  3. //----------------------------------
  4.  
  5. // Okay, so I know how to output a couple of sentences onto the screen.
  6. // A week should have already passed if I were studying this on
  7. // my own. Outrageous isn't it?
  8. // I remembered when I first started, I was told to go install this,
  9. // go install that, make this run.
  10. // It felt like a cat and mouse game.
  11. // I kept on moving around and I didn't know if I was making any progress or not. There were
  12. // so many code editors out there and I didn't know which was good or not.
  13. // No tutorial was there to help and it basically took me
  14. // almost a week to get my first code out. Very strange indeed.
  15.  
  16. // By now, the most infamous "Hello World" example should be a breeze and accomplishable.
  17. // Hint: (Just output "Hello World")
  18. // I am or should be ready to tackle problems!! Yes? Let's start!
  19. // The next on the list are "If and While Statements".
  20.  
  21. //----------------------------------
  22. // Week 2.1 : If Statements
  23. //----------------------------------
  24.  
  25. // What does the word "If" mean in English?
  26. // I remembered when I first taught English,
  27. // this was also a very important "grammar structure" that most of my ESOL students
  28. // had to learn. The way I structured it was...
  29.  
  30. // If ..... Then.....
  31. // If I went to play ball, then the dogs would come out.
  32. // If (condition), then (action)
  33.  
  34. // In code, this follows the exact structure.
  35. // Here is the syntax for if C++ statements.
  36.  
  37. // if (condition)
  38. // {then this code run};
  39.  
  40. //----------------------------------
  41. // Week 2.15 : If Statements Example Code
  42. //----------------------------------
  43.  
  44. // Try running the code below and see if it works or not.
  45. // Then try
  46.  
  47. #include <iostream>
  48.  
  49. int main()
  50. {
  51. int x = 10;
  52. if (x = 10)
  53. {
  54. std::cout << "Yes, X is 10";
  55. }
  56. else
  57. {
  58. std::cout << "No, X does not equal 10";
  59. }
  60. }
  61.  
  62. //----------------------------------
  63. // Week 2.175 : If Statements Example Code Comment
  64. //----------------------------------
  65.  
  66. // What the? Did I see an extra line of code?
  67. // What are these extra line of codes?
  68. // Well, let's break it down.
  69.  
  70. // int x = 10;
  71.  
  72. // x is the variable name. A variable name is a name that you
  73. // use to label any variable. It can be x, y, hotdog, pizza, anything you want.
  74. // int is short for integer.
  75. // An integer is a number that is whole; -200, 5, 75.
  76. // int is the datatype that you decided for the variable.
  77.  
  78. // Example:
  79. // When I tell you that I have the letter X in my hand and it means something,
  80. // that doesn't really help much. However, when I tell you that this letter X is an integer,
  81. // now it brings a lot more info to the table. Oh, so I see that the X in my hand is an integer!
  82. // Now afterward, we must set the value of the X,
  83. // in which we add the "=" symbol and now X equals 10.
  84. // A datatype is used for clarification purposes and allows us to understand
  85. // what type of data we are working with.
  86. // When declaring (creating) new variables, we must set the datatype before the variable name.
  87.  
  88. // Declaring
  89. // int y;
  90.  
  91. // Intializing (setting a value to a variable)
  92. // y = 10;
  93.  
  94. // Declaring and Initializing
  95. // int z = 50;
  96.  
  97. //// Else Statements ////
  98.  
  99. // Now, what we saw an if statement, but we also saw an else too!
  100. // What does this mean overall?
  101.  
  102. // In English, we would say...
  103. // If I am going to the park, I want to find a cheetah.
  104. // If I go to the park I want to find a cheetah, else I am going downtown to skateboard.
  105. // Mathematically...
  106. // If (this happens), then (do this)
  107. // If (this doesn't happen), else (this happens)
  108.  
  109. // Fill in the blanks
  110.  
  111. #include ________
  112.  
  113. int main()
  114. {
  115. ___ hamburgers = _ ;
  116.  
  117. if (hamburgers = 3)
  118. {
  119. std::cout __ "I am hungry";
  120. }
  121. else
  122. _________ << "I need money"_
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement