Question: #include #include #include #include using namespace std; const int attempts=5; int letterFill (char, string); int main (){ string name; char letter; int num_of_wrong_guesses=0; string word;
#include
#include
#include
#include
using namespace std;
const int attempts=5;
int letterFill (char, string);
int main (){
string name;
char letter;
int num_of_wrong_guesses=0;
string word;
// welcome to the Harsh World of Guessing
cout << " Welcome to the Konya boys word guessing game";
cout << " Each letter is represented by a star.";
cout << " You have to type only one letter in one try";
cout << " You have " << attempts << " tries to try and guess the word.";
cout << " You have have a maximum number of tries, however if you miss all the fibe tries you get hit in the head ";
cout << " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << " Player one, enter a random word: ";
cin >> word;
// Loop until the guesses are used up
bool guess = false;
while (num_of_wrong_guesses < attempts && guess==false )
{
cout << " Guess a letter: ";
cin >> letter;
// Fill secret word with letter if the guess is correct,
// otherwise increment the number of wrong guesses.
if (letterFill(letter, word)==0){
cout << endl << "Whoops! That letter isn't in there!" << endl;
num_of_wrong_guesses++;
}
else
{
cout << endl << "You found a letter! Isn't that exciting!" << endl;
}
// Tell user how many guesses has left.
cout << "You have " << attempts - num_of_wrong_guesses;
cout << " guesses left." << endl;
// Check if user guessed the word.
// if (word==word){
// cout << word << endl;
// cout << "Yeah! You got it!";
// break;
}
if(num_of_wrong_guesses == attempts){
cout << " Sorry, you lose...you are going to be Konyad and guess again." << endl;
cout << "The word was : " << word << endl;
}
cin.ignore();
cin.get();
return 0;
}
/* Take a one character guess and the secret word, and fill in the
unfinished guessword. Returns number of characters matched.
Also, returns zero if the character is already guessed. */
int letterFill (char guess, string secretword)
{
int i;
int matches=0;
int len=secretword.length();
for (i = 0; i< len; i++)
{
// Did we already match this letter in a previous guess?
if (guess == secretword[i])
matches++;
// Is the guess in the secret word?
}
return matches;
}
Please finish this code for me.. It is supposed to work like Hanged man game project but I dont know how to end. what I want it it do is to print the name of the Word the person guesses in object oriented programming.. please run it and see where you can fix thank you.. It is due today
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
