Building A Guessing Game

Lesson 23
Author : Afrixi
Last Updated : November, 2017


Table of Content

Code

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

while(guess != secretNum && outOfGuesses == 0){
     if(guessCount < guessLimit){
          printf("Enter a guess: ";
          scanf("d", &guess);
          guessCount++;
     } else {
          outOfGuesses = 1;
     }
}

if(outOfGuesses != 0){
     printf("You Lose!");
} else {
     printf("You Win!");
}