Lesson 11: Case study – Using loops to make a simple number guessing game

Homework: http://beginnerscpp.com/forums/index.php/topic,63.0.html

Number guessing game
This number guessing game is an example of the type of program you can make with what you’ve learned up to this point with C++ using loops, and if statements. You could easily make far more complex games than this, but for a 15 minute (self-imposed) time limit, it’s not too bad. We cover a few concepts in this video that I want to put into writing.

Sentinel Loops
While we don’t directly use a sentinel loop in our program we use a bool to do roughly the same thing. A sentinel loop is a loop that is “broken” (exited) when a specific value becomes true. In this case we’re checking our variable “quit” to see if it becomes equal to y, then setting a boolean variable to false. The more ‘classic’ implementation of a sentinel loop is something like this:

Lesson 10: Nested Loops
Lesson 12: Working With Strings