Question: I have the following code and I do not know how to change it in order to do what the picture is asking for. Need
I have the following code and I do not know how to change it in order to do what the picture is asking for. Need Help ASAP
#include
#include
#include
#include
using namespace std;
const int MAX_TRIES=5;
int letterFill (char, string, string&);
int main ()
{
string name;
char letter;
int num_of_wrong_guesses=0;
string word;
string words[] =
{
"india",
"pakistan",
"nepal",
"malaysia",
"philippines",
"australia",
"iran",
"ethiopia",
"oman",
"indonesia"
};
//choose and copy a word from array of words randomly
srand(time(NULL));
int n=rand()% 10;
word=words[n];
// Initialize the secret word with the * character.
string unknown(word.length(),'*');
// welcome the user
cout
cout
cout
cout
cout
// Loop until the guesses are used up
while (num_of_wrong_guesses
{
cout
cout
cin >> letter;
// Fill secret word with letter if the guess is correct,
// otherwise increment the number of wrong guesses.
if (letterFill(letter, word, unknown)==0)
{
cout
num_of_wrong_guesses++;
}
else
{
cout
}
// Tell user how many guesses has left.
cout
cout
// Check if user guessed the word.
if (word==unknown)
{
cout
cout
break;
}
}
if(num_of_wrong_guesses == MAX_TRIES)
{
cout
STEP 1 Create a UML class diagram for a class you create 2. Code your class. 3. Test your class. Turn in: UML Class Diagram, C++ Code for class and test driver. STEP 1 Create a UML class diagram for a class you create 2. Code your class. 3. Test your class. Turn in: UML Class Diagram, C++ Code for class and test driver cout
}
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, string &guessword)
{
int i;
int matches=0;
int len=secretword.length();
for (i = 0; i
{
// Did we already match this letter in a previous guess?
if (guess == guessword[i])
return 0;
// Is the guess in the secret word?
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
