Create a program that plays the game of \"HANGMAN\" (guessing a mystery word). R
ID: 3546255 • Letter: C
Question
Create a program that plays the game of "HANGMAN" (guessing a mystery word). Read a word to be guessed from a file into successive elements of the array "WORD." The player must guess the letters belong to "WORD." A single guessing session should be terminated when either all letters have been guessed correctly (player wins) or a specified number of incorrect guesses have been made (computer wins). A run must consist of at least two sessions: one player wins and one computer wins. The player decides whether or not to start a new session.
Hints:
Use an array SOLUTION to keep track of the solution generated thus far. Initialize SOLUTION to a strong of symbols "*". Each time a letter of "WORD" is guessed, replaced the correponding "*" in SOLUTION with that letter. For example, cin >> Guess; if (Guess == WORD[index] ) {SOLUTION[index] = Guess}
You may consider using the following functions:
- Initialize: initialize SOLUTION to *'s and other global variables to 0.
- Guess: process guessed of the mystery word. Read in guesses until the limit is reached or the word is guessed. If the guessed letter is not in the word, inform the player. Otherwise, tell the player the number of times the letter occurs in the word and display the partial solution to the user.
- Readstring: Before running the program, prepare a file containing 20 words, each on a separate line. At the beginning of each session, read a word from the file into the strong named WORD.
- PrintSolution: print the guessed word and the number of times the player has tried.
- GuessedWord: It is a function. It returns TRUE if every element of SOLUTION is not a *.
and other functions if needed:
- MainProgram: control when to stop the loop, call functions, and print out the player's scores in terms of wins.
- Pay attention to the differences between value and variable paramters.
- Run the program three times and print the execution step by stem
- To make the output interesting and to earn extra points, you may want to draw a figure on the screen step by step.
Thanks.
Explanation / Answer
for the secret word in hangman, how do i make special symbols like ! and @, etc, not be blocked by dashes? For example, if the word was CALIFORNIA! It should output it as ----------! when trying to guess, See how it doesn't block the exclamation with a dash or cover it, how would I be able to do that? Thanks a lot. My code is below:#include "stdafx.h" #include #include #include #include #include #include using namespace std; char getGuess(string &used); //Prototype Function Declaration char EntryIsCorrect(); //Prototype Function Declaration int main() { // set-up const int MAX_Incorrect = 5; // maximum number of incorrect guesses allowed vector words; // collection of possible words to guess words.push_back("CALIFORNIA"); srand(static_cast(time(0))); random_shuffle(words.begin(), words.end()); const string SECRET_WORD = words[0]; // word to guess int wrong = 0; // number of incorrect guesses string soFar(SECRET_WORD.size(), '-'); // word guessed so far string used = ""; // letters already guessed coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.