I am trying to build a simple console app game, Hangman! I have a while loop that repeats while the counter is not equal to the maximum number of guesses, however, I would like for the loop to break and end the program when one of the two conditions is met, either counter equals the maximum number of guesses, OR when the users guess the word.
here is some of my code:
char[] Guess_Word = "ab".ToLower().ToArray();
char[] GuessValues = new char[Guess_Word.Length];
//run while loop to display message instructions
while ((Counter != Max_Guess) || (Guess_Word == GuessValues))
{
Console.Write("\n\nEnter a letter: ");
Letter = Char.ToLower(Convert.ToChar(Console.ReadLine()));
//testing to see if the letter is in word
if (Guess_Word.Contains(Letter))
{
Console.WriteLine("You've guessed correctly!");
for (var i = 0; i < Guess_Word.Length; i++)
{
if (Letter == Guess_Word[i])
{
GuessValues[i] = Guess_Word[i];
}
}
Correct_Guess++;
Console.WriteLine(GuessValues);
}
else
{
Console.WriteLine("You've guessed incorrectly!");
Console.WriteLine(GuessValues);
Incorrect_Guess++;
}
Counter++;
}
The second conditional statement in the while loop is always false, even when the indexes have the same values.