Write an interactive program that plays a game of hangman. Store the word to be
ID: 3743771 • Letter: W
Question
Write an interactive program that plays a game of hangman. Store the word to be guessed in successive elements of a 1-dimensional array of individual characters named word. The program should terminate when either all letters have been guessed correctly (the player wins) or a specified number of incorrect guesses have been make (the computer wins).
Hint: Use a second 1-dimensional array of characters guessed, to keep track of the solution so far. Initialize all elements of guessed to the ‘*’ symbol. Each time a letter in word is guessed, replace the corresponding ‘*’ in guessed with that letter.
Your program should be modular, with separate functions for input, each part of the processing and output. Your output should be well-organized, neat, and easy to read.
Explanation / Answer
Solution:
Sample execution for the word “rhythm” read from the input file:
Hi, let's play hangman.
The secret word is:
******
Guess a letter: a
Letter a is not part of the secret word.
******
Guess a letter: h
Letter h exists 2 time(s) in the secret word.
h**h
Guess a letter: ?
Sorry „?? is not a letter.
h**h
Guess a letter: e
Letter e is not part of the secret word.
h**h
Guess a letter: r
Letter r exists 1 time(s) in the secret word.
rh**h*
Guess a letter: s
Letter s is not part of the secret word.
rh**h*
Guess a letter: t
Letter t exists 1 time(s) in the secret word.
rh*th*
Guess a letter: y
Letter y exists 1 time(s) in the secret word.
rhyth*
Guess a letter: m
Letter m exists 1 time(s) in the secret word.
rhythm
Bravo! You have guessed the full secret word.
Do you want to play again? (Y/N): N
THANK YOU FOR PLAYING HANGMAN
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.