C++ - Programming Language
This course covers the basics of programming in C++. Work your way through the videos and we'll teach you everything you need to know to start your programming journey!

Building A Guessing Game

Lesson 21
Author : Mike Dane
Last Updated : November, 2017


Code

Copyint secretNum = 7;
int guess;
int guessCount = 0;
int guessLimit = 3;
bool outOfGuesses = false;

while(guess != secretNum && !outOfGuesses){
     if(guessCount < guessLimit){
          cout << "Enter a guess: ";
          cin << guess;
          guessCount++;
     } else {
          outOfGuesses = true;
     }
}

if(outOfGuesses){
     cout << "You Lose!" << endl;
} else {
     cout << "You Win!" << endl;
}