I am having a really hard time updating the array for char. I am making hangman game, in which
char board[WORD_LENGTH+1] = "-----";
and in the following function every time user makes a right guess board needs to update the letters precisely to match the words, but leave rest of the words until next guess is made.
Below is what i have but it only updates the first word 5 times and then nothing happens in the next guess.
Please help thanks
1 2 3 4 5 6 7 8 9 10 11 12
// Update the board array to put the char guess whereever
// it appears in the word array. For example, if the word equals
// "every", board equals "-----", and guess equals "e", then
// board should be updated to equal "e-e--"
void updateTemplate(char guess, char word[], char board[])
{
for (int n=0; n < WORD_LENGTH ; n++)
{
if ( word[n] == guess )
cout << guess<< board[n]<< endl;
}
}
The characters in board[] won't be changed in either version of your function. There are no assignments being made. eg.board[0] == word[0]; is not an assignment. Use = not == for assignment. sohguanh explained that already.
Also, your 2nd version wouldn't catch the 2nd 'e' in your example. The loop in your 1st version would though if an assignment were made there.