i have a text document with 10 words to guess. i have the code already read a random word from the file. then the user guesses a letter and it finds whether or not if the letter is in the word. my problem is how can i have it remember the previous letter and outcome and builds on so it will complete the entire word. my teacher said this as a hint " I suggest you make a word of all blanks
then replace letters with the letters that are in the word to be guessed
you can use the position found by find to put the letter in the appropriate position." but how would i go about doing that any help would be greatly appreciated.
Somewhere you have a string that stores the word you want the user to guess (you named it "word", but I would have named it something like "word_to_guess").
And you have to keep track of what letters have already been guessed that: 1) are in the word, and 2) that are not in the word. Since either way the letter has already been guessed, this suggests to me a string to remember them ("letters_guessed").
But you also need to know how much of the puzzle has been solved. This suggests one more string "word_guessed_so_far" or somesuch.
You can then compare the "word_to_guess" and "word_guessed_so_far" to see if the user has completed the puzzle:
1 2
"hello world" <-- word_to_guess
" ello o l " <-- word_guessed_so_far
The last thing you need is a function that will display the word guessed so far to the user in a fancy way, like _ e l l o _ o _ l _
thanks for the help, i changed code and it enters the guessed letters into a blankword. how could i compare blankword[4] to word so if the word guessed so far is equal to the word to be guessed are equal then it prints out a congratulations or if not then you lose. also how should i call the drawings should i use a switch statement like i have and if so how should i call it to draw