Blog

July 25, 2015

The Great Psychic Hobo – Do/While loops

DoWhile001 OK, so I have a fun little plan to help me expedite my programming endeavor. I’m going to track my progress on my Blog here. I added a Programming tag to the posts, so I can view by category whenever I need a refresher of what I’ve already done. I think this would be a good way to monitor progress and keep things consistently moving.


So tonight’s lesson was Strings, Player Input and Do / While loops. So we define a string (a series of characters), and define an Integer which in this case is = to 0.

We start the Do loop with the brackets and type on screen with cout a question about what number the Great Psychic Hobo is thinking of. We then use the getline with cin to get keyboard input using the pickNumber String. The next line we convert the String into an Integer using = stoi, then output the result with the next cout << intPickNumber line.

Finally we finish with the While loop which defines the number in the Hobo’s head, making the user keep guessing with any number that is not (!) = to 7.

If the number the user chooses is 7, then we display the last line cout “You Win Pecker!!” , and in the output window, we see that the Psychic Hobo’s number he had in his head was Indeed, “7”. Yeayyyy!!! lol. So to sum up, the Do loop sets up the question and keyboard input, while the While loop holds on to the answer until the user picks the correct number defined, then lets the user know they guessed correctly when they finally input the correct number.

So this is my first of many posts to come related to programming. I know, baby steps, but I’m having a lot of fun with it.

Programming
About admin

Leave a Reply