Building A Guessing Game
Lesson 19Author : GOUP
Last Updated : September, 2020
Code
string secretWord = "giraffe";
string guess = "";
int guessCount = 0;
int guessLimit = 3;
bool outOfGuesses = false;
while(!guess == secretWord && !outOfGuesses){
if(guessCount < guessLimit){
Console.Write("Enter a guess: ");
guess = Console.ReadLine();
guessCount++;
} else {
outOfGuesses = true;
}
}
if(outOfGuesses){
Console.WriteLine("You Lose!");
} else {
Console.WriteLine("You Win!");
}