I am working on a console Hangman game in c#. I am trying to compare user inputted letter against the letters in the random word I have generated. Error i get is "Operator "==" cannot be applied to operands of type "string" and "char". What other ways could I go about doing this? Ive googled a lot but I haven't found any ideas.
public static void LetterChecker(string word)
{
int userGuesses = 6;
string userInputGuess;
while(userGuesses > 0)
{
Console.WriteLine("Please guess a letter");
userInputGuess = Console.ReadLine();
foreach(var letter in word)
{
if(userInputGuess == letter)
{
Console.WriteLine("this letter is in word, guess again");
}
else
{
Console.WriteLine("Incorrect guess");
userGuesses--;
}
}
}
}
Console.ReadKey().KeyCharinstead ofConsole.ReadLine()since you want only a single character from the user.if(userInputGuess[0] == letter)