Question
Write the algortithm for the program bescribed below The algorithm is the logical order of the steps of the program you will be implementing. The
Write the algortithm for the program bescribed below
The algorithm is the logical order of the steps of the program you will be implementing.
The algorithm does not include any C language specific elements like functions.
Write an interactive program that will allow a user to play the game of Hangman. You will need to:
?You will use four character arrays:one for the word to be guessed(solution)
one for the word in progress (starword)
one for all of the guessed letters
(letters)
one for the users word guess (guess)
?Declare additional variables as needed
?At the beginningof each game:
word to be guessed
array
-
start with an empty string
.
?Read a word from the file and store it in the word to be guessed array.
word in progress array should be adjusted to the correct length (that is the same size as the word read
from the file but consists only of * (asterisks)
in the beginning
(starword)
guessed letters array should be empty
a character is added with each guess
?An integer will keep track of how many characters are in the array
HOW TO PLAY THE
GAME
?Allow the user to guess letters one character at a time.
? At every stage of the game, the user should be able to view the current state of the word in progress(starword) and the list of guessed letters (letters)
? If any letter is correctly guessed the player is notified and the letter appears in its proper location in the word in progress array (starword),this array is displayed again with the letter(s)
in place and the user can input a word
?If a letter is not correct, the number of used guesses is increased.
?In ALL cases, the guessed letter should be added to the array of guessed letters
?The user is allowed up to 6 incorrect guesses.
?The game is over when the word is guessed correctly or the six incorrect guesses are used up.
?If the player guesses the word correctly, the player is notified that they have won and the correct word is displayed.
?If the player does not get the correct word, the player is notified that they have lost and the correct word is displayed.
?When the game is over, the user should be allowed to play again without having to execute the program again.(The player will play again with the next word in the file)
Other Requirements
?You must have meaningful variable and function names.
?You must use consistent and proper indentation
?You must use sufficient comments that tell a programmer what is happening in the program
?You must have at least 8 user
-defined functions with meaningful names that perform the specified tasks:
A function that displays the instructions
/ rules on how to play the game.
A function that determines if the player would like to play again(y or n)
A function that plays one round of the game
A function that changes a character array to all upper case or all lower case letters
A function that creates the starword , an array of * the same size as the solution word
A function that gets a character from the user and adds that character to an array of all the letter that have been guessed
A function that searches the solution word and replaces any asterisks in the starword with the character
A function that gets a guess word from the user, compares it to the solution and tells the user if they won
?You must use function prototypes
placed before the main function and all function definitions must follow
the main function.
?All function prototypes and definitions must have a comment describing what the function does.
#define_CRT_SECURE_NO_WARNINGS
#include
#include
#include
#defineMAXGUESSES6
SampleOutput:
WELCOME TO HANGMAN!
Please read the following instructions before you play.
-
You will be presented with a word to be guessed
-
Guess letters one at a time
-
You can have up to six incorrect letter guesses
-
You can only guess the word when you have made a correct letter guess
-
The game will be OVER when you have guessed the word correctly
Or when you have guessed letters incorrectly SIX times.
HAVE FUN!
Here are the letters guessed so far:
*********
Guess a letter: n
-----------------------
--------
The letter was in the word, you can now guess the word:
*N*******
Guess the word: answering
That is not the correct word
3
Here are the letters guessed so far: N
*N*******
Guess a letter: w
The letter was not in the word, the value of wrongGu
esses is now 1
Here are the letters guessed so far: NW
*N*******
Guess a letter: e
-------------------------------
The letter was in the word, you can now guess the word:
*N**E****
Guess the word: understand
That is not the correct word
Here are the
letters guessed so far: NWE
*N**E****
Guess a letter: u
-------------------------------
The letter was in the word, you can now guess the word:
UN**E****
Guess the word: universal
You won that round, congratuations!
Would you like to play another r
ound (y or n)? y
Here are the letters guessed so far:
********
Guess a letter: r
-------------------------------
The letter was in the word, you can now guess the word:
*******R
Guess the word: forever
That is not the correct word
Here are the
letters guessed so far: R
*******R
Guess a letter: e
-------------------------------
The letter was in the word, you can now guess the word:
E****EER
Guess the word: engineer
4
You won that round, congratuations!
Would you like to play another round (y
or n)? y
Here are the letters guessed so far:
*****
Guess a letter: o
The letter was not in the word, the value of wrongGuesses is now 1
Here are the letters guessed so far: O
*****
Guess a letter: p
The letter was not in the word, the value of wrongGuesses is now 2
Here are the letters guessed so far: OP
*****
Guess a letter: r
-------------------------------
The letter was in the word, you can now guess the word:
R***R
Guess the word: rover
Tha
t is not the correct word
Here are the letters guessed so far: OPR
R***R
Guess a letter: i
The letter was not in the word, the value of wrongGuesses is now 3
Here are the letters guessed so far: OPRI
R***R
Guess a letter: e
The letter was not in the word, the value of wrongGuesses is now 4
Here are the letters guessed so far: OPRIE
R***R
Guess a letter: u
The letter was not in the word, the value of wrongGuesses is now 5
Here are the letters guessed so far: OPRIEU
R***
R
Guess a letter: x
5
The letter was not in the word, the value of wrongGuesses is now 6
You did not win this round, the solution was RADAR
Would you like to play another round (y or n)? n
Press any key to continue . . .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started