Building A Guessing Game
Lesson 23Author : GOUP
Last Updated : September, 2020
Code
int 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!");
}