Problem: Write an interactive program that plays a game of hangman. Initialize an array of type char (string) with the secret puzzle. Note: a few puzzles for this problem are from the text file of the final project.
Initially the program prints on the screen the number of letters of the word to be guessed. This is in the form of successive _ (see example below). The player guesses letters belonging to the secret puzzle one by one.
At each step, the program prints on the screen the letters that are correctly guessed (part of the secret puzzle) and number of times that the correct letter are in the secret puzzle, and the letters that are already used. See sample code execution.
The program should terminate when all letters have been guessed correctly.
Hint: Use another array, Guessed, to keep track of the solution so far. Initialize all elements of guessed to the '_' symbol. Each time a letter in puzzle is guessed correctly, replace the corresponding '_' in Guessed with that letter.
You are encouraged to create at least 1 meaningful user-defined function(s) that abstract details such as array printing, array initializing, or array searching (functions you deem as necessary). The functions must have array(s) as the function arguments see section 6.10 in the Zyante book or lecture_set10 starting from slides 19.
Test your program for secret puzzles: CHEESE AND CRACKERS, MANICURE & PEDICURE Clue for each puzzle: Food & Drink, Things
Note: For this problem, one of the secret puzzles is initialized in your program. For your final project, one of the puzzles in each round is randomly chosen from all the puzzles given in the text file. Each puzzle can have any number of characters.
Hi, let's play Hangman. The clue is: Things
The secret puzzle is: _ _ _ _ _ _ _ _ & _ _ _ _ _ _ _ _
Guess a letter: o
Letter o is not part of the secret puzzle
, _ _ _ _ _ _ _ _ & _ _ _ _ _ _ _ _
Letter already guessed: o
Guess a letter: e
Letter e was found 3 times in the secret puzzle
_ _ _ _ _ _ _ E & _ E_ _ _ _ _ E
Letter already guessed: o e
Guess a letter: P
Letter P was found 1 times in the secret puzzle
_ _ _ _ _ _ _ E & PE_ _ _ _ _ E
Letter already guessed: o e P
Guess a letter: D
Letter D was found 1 times in the secret puzzle
_ _ _ _ _ _ _ E & PED_ _ _ _ E
Letter already guessed: o e P D
Guess a letter: A
Letter A was found 1 times in the secret puzzle
_ A_ _ _ _ _ E & PED_ _ _ _ E
Letter already guessed: o e P D A
Guess a letter: m
Letter m was found 1 times in the secret puzzle
MA_ _ _ _ _ E & PED_ _ _ _ E
Letter already guessed: o e P D A m
Guess a letter: C
Letter C was found 2 times in the secret puzzle
MA_ _ C_ _ E & PED_ C_ _ E
Letter already guessed: o e P D A m C
Guess a letter: u
Letter u was found 2 times in the secret puzzle
MA_ _ CU_ E & PED_ CU_ E
Letter already guessed: o e P D A m C u
Guess a letter: r
Letter r was found 2 times in the secret puzzle
MA_ _ CURE & PED_ CURE
Letter already guessed: o e P D A m C u r
Guess a letter: i
Letter i was found 2 times in the secret puzzle
MA_ ICURE & PEDICURE
Letter already guessed: o e P D A m C u r i
Guess a letter: n
Letter n was found 1 times in the secret puzzle
MANICURE & PEDICURE
Letter already guessed: o e P D A m C u r i n
Congratulations! You solve the puzzle: MANICURE & PEDICURE