2. Control Flow
Activity 2: Creating a Number-Guessing Game Using Loops and Conditional Statements
Solution:
- Declare all the variables we'll need. This includes
guessCount
,minNumber
,maxNumber
, andrandomNumber
:// Activity 2: Number guessing game. #include <iostream> #include <string> int main() { // Declare variables. int guessCount = 0; int minNumber = 0; int maxNumber = 0; int randomNumber = 0; std::string input = ""; bool bIsRunning = true;
- Create a main outer loop that will run the application:
while (bIsRunning) { }
- Present the user with some introductory text (
"Enter the number of guesses"
) and get from them the following: a number of guesses, a minimum number, and a maximum number:&...