Building A Guessing Game
Lesson 19Author : 🦒
Last Updated : November, 2017
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!");
}