Question
Write a C++ hangman game using at least 5 user defined functions. The secret hangman word will come from an input file. I cannot use
Write a C++ hangman game using at least 5 user defined functions. The secret hangman word will come from an input file. I cannot use any arrays or vectors, this must be accomplished with loops
Function 1 should prompt user for game number. If the user types "3" then the third word in the file will be used.
Function 2 should read the word from an input file. If the game number chosen from function 1 is less than zero then a randomly selected word will be used.
Function 3 will print the correct hangman picture based on the number of wrong guesses. See below for example of hangman picture
Function 4 will make a copy of the secret word and replace all letters with ***** then print
Function 5 will allow the user to make the next guess and change the **** to letters if a correct letter is chosen
These are basic guidelines, some variation is okay
hangman looks somethin like this:
void printHangman(int wrongGuesses )
{
if (wrongGuesses == 6)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | /|\\ " << endl
<< " | / \\ " << endl
<< " | " << endl;
}
else if (wrongGuesses == 5)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | /|\\ " << endl
<< " | / " << endl
<< " | " << endl;
}
else if (wrongGuesses == 4)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | /|\\ " << endl
<< " | " << endl
<< " | " << endl;
}
else if (wrongGuesses == 3)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | /| " << endl
<< " | " << endl
<< " | " << endl;
}
else if (wrongGuesses == 2)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | | " << endl
<< " | " << endl
<< " | " << endl;
}
else if (wrongGuesses == 1)
{
cout << endl << endl
<< " -------- " << endl
<< " | O " << endl
<< " | " << endl
<< " | " << endl
<< " | " << endl;
}
}
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