Does anyone know why I only get the first letter correct? When I try to guess the letter "h" or any other correct letter, it prints out "try again" instead of "You guessed a letter"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
bool checkGuess(char answer[], char guess, int size)
{
for (int i = 0; i < size; i++)
{
if (guess == answer[i])
{
returntrue;
}
elseif (guess != answer[i])
{
returnfalse;
}
}
}
Take a look at the logic of your checkGuess() function. You only check the first element of your answer array and return true or false. You don't check any of the other array's elements.
1 2 3 4 5 6 7 8 9 10 11 12
bool checkGuess(char answer[], char guess, int size)
{
for (int i = 0; i < size; i++)
{
if (guess == answer[i])
{
returntrue;
}
}
returnfalse;
}
I was looking at it wrong. I didn't realize you put "return false;" outside of the for loop! No wonder it still wasn't making any sense to me! Thank you so much!