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

Building A Guessing Game

Lesson 21
Author : GOUP
Last Updated : September, 2020


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;
}