Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------
- // Week 2 : If and Else Statements
- //----------------------------------
- // Okay, so I know how to output a couple of sentences onto the screen.
- // A week should have already passed if I were studying this on
- // my own. Outrageous isn't it?
- // I remembered when I first started, I was told to go install this,
- // go install that, make this run.
- // It felt like a cat and mouse game.
- // I kept on moving around and I didn't know if I was making any progress or not. There were
- // so many code editors out there and I didn't know which was good or not.
- // No tutorial was there to help and it basically took me
- // almost a week to get my first code out. Very strange indeed.
- // By now, the most infamous "Hello World" example should be a breeze and accomplishable.
- // Hint: (Just output "Hello World")
- // I am or should be ready to tackle problems!! Yes? Let's start!
- // The next on the list are "If and While Statements".
- //----------------------------------
- // Week 2.1 : If Statements
- //----------------------------------
- // What does the word "If" mean in English?
- // I remembered when I first taught English,
- // this was also a very important "grammar structure" that most of my ESOL students
- // had to learn. The way I structured it was...
- // If ..... Then.....
- // If I went to play ball, then the dogs would come out.
- // If (condition), then (action)
- // In code, this follows the exact structure.
- // Here is the syntax for if C++ statements.
- // if (condition)
- // {then this code run};
- //----------------------------------
- // Week 2.15 : If Statements Example Code
- //----------------------------------
- // Try running the code below and see if it works or not.
- // Then try
- #include <iostream>
- int main()
- {
- int x = 10;
- if (x = 10)
- {
- std::cout << "Yes, X is 10";
- }
- else
- {
- std::cout << "No, X does not equal 10";
- }
- }
- //----------------------------------
- // Week 2.175 : If Statements Example Code Comment
- //----------------------------------
- // What the? Did I see an extra line of code?
- // What are these extra line of codes?
- // Well, let's break it down.
- // int x = 10;
- // x is the variable name. A variable name is a name that you
- // use to label any variable. It can be x, y, hotdog, pizza, anything you want.
- // int is short for integer.
- // An integer is a number that is whole; -200, 5, 75.
- // int is the datatype that you decided for the variable.
- // Example:
- // When I tell you that I have the letter X in my hand and it means something,
- // that doesn't really help much. However, when I tell you that this letter X is an integer,
- // now it brings a lot more info to the table. Oh, so I see that the X in my hand is an integer!
- // Now afterward, we must set the value of the X,
- // in which we add the "=" symbol and now X equals 10.
- // A datatype is used for clarification purposes and allows us to understand
- // what type of data we are working with.
- // When declaring (creating) new variables, we must set the datatype before the variable name.
- // Declaring
- // int y;
- // Intializing (setting a value to a variable)
- // y = 10;
- // Declaring and Initializing
- // int z = 50;
- //// Else Statements ////
- // Now, what we saw an if statement, but we also saw an else too!
- // What does this mean overall?
- // In English, we would say...
- // If I am going to the park, I want to find a cheetah.
- // If I go to the park I want to find a cheetah, else I am going downtown to skateboard.
- // Mathematically...
- // If (this happens), then (do this)
- // If (this doesn't happen), else (this happens)
- // Fill in the blanks
- #include ________
- int main()
- {
- ___ hamburgers = _ ;
- if (hamburgers = 3)
- {
- std::cout __ "I am hungry";
- }
- else
- _________ << "I need money"_
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement