Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thank you in advance . You will be creating a Hangman program. In this game, the

ID: 3847264 • Letter: T

Question

Thank you in advance . You will be creating a Hangman program. In this game, the computer will have a hard coded word and the user will enter one letter at a time until he or she has guesses the correct word. A score will be tallied that will be the number of incorrect guesses the user has. So a smaller score is better. Initially the word will be displayed as a list of special characters such as or The user will input one letter at a time and each input will be compared with the word. If the guess is correct the letter will be displayed rather than the special character. Each incorrect guess will increment the score. When the user guesses the correct word the game will be over Design and code the program to display the input and output for the Hangman program. Use your last name as the word to guess. Each letter will be a char data type. Start by having the user enter 5 letters to guess. See below: Modify the design and program to test if each letter the user entered is one of the letters in the word. If the letter guessed is in the word, display a message to the user that they guessed correctly, if not display a message that the user guessed incorrectly. Add a score variable that will keep track of the number of incorrect guesses. If the user guesses incorrectly, increment the score variable. Display the score at the end of the program Modify the design and program to allow for iteration. Increase the number of guesses to 10 to solve the word. Display the word to the user with each letter as a special character such as Create an array of correct letters guessed such as: CharU guessed new char[26] You will need counter also to keep track of how many letters are in the guessed array. You do not need to keep track of incorrectly guessed letters. This is your final modification to the project. Modify the design and program of the program so that the word is stored as an array. You can use code such as the following: charU word happy" rArr Where "happy" is replaced with your name. Add a for loop to display each letter in the word character array. If it has been guessed correctly, display the correct letter, if not display the special character.

Explanation / Answer

//use the below hangman sample program.
//total guesing is 10, you can modify the code to increase.

#include <iostream>
#include <string>
using namespace std;

int main()
{
cout << "Enter the word for other player to guess" << endl;
  
string word;
getline(cin, word);
  
string copy = word;

string Underscore;
  
for(int i=0; i!=word.length(); i++){

if(word.at(i) == ' '){
Underscore += " ";
} else{
Underscore += "_";
}
}
  
for(int i=0; i!=50; ++i){
cout << endl;
}
  
string guess;
int wrong=0;
  
while(1){
if(wrong == 10){
cout << "You Lose! The word was: " << word << endl;
break;
}

cout << Underscore << endl;
cout << "There are " << word.length() << " letters with spaces" << endl;
cout << "You have " << 6 - wrong << " more tries left" << endl;

if(Underscore == word){
cout << "You win!" << endl;
break;
}

cout << "Guess a letter or a word" << endl;
getline(cin, guess);
  
if(guess.length() > 1){
if(guess == word){
cout << "That's right, you win!" << endl;
break;
} else{
cout << "wrong word " << endl;
wrong++;
}
} else if(copy.find(guess) != -1){
while(copy.find(guess) != -1){
Underscore.replace(copy.find(guess), 1, guess);
copy.replace(copy.find(guess), 1, "_");
}
} else{
cout << "That's wrong" << endl;
wrong++;
}
  
cout << endl;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote