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

The word to guess cannot have repeated letters The word to guess is not case sen

ID: 3623377 • Letter: T

Question

The word to guess cannot have repeated letters The word to guess is not case sensitive The guessing player has 10 tries to find the letters. The player cannot guess the entire word in one shot. S/he must use strings for world that is to be guessed as well as the list of letters still left to try. You can use any kind of loop you like. Your output does not have to be formatted exactly as the sample runs but should contain the same information. Recommended skeleton of the structure of your program: A player enters the word to guess. Remember a word can only have letters and no repeated letters 20 or blank lines are printed to clear the word to guess from the screen, before guessing player starts. Guessing player (the other player) is shown with dashes (or starts) the number of letters in the word to guess. Your program also shows the number of guesses left as well as a list of the letters still not picked(See sample run at the end of this explanation) Guessing player is prompted for a letter. As long as the input is more than one character long, is not a letter or is a letter that was already tried, your program keeps prompting keeps prompting the user for input. Incorrect entries should not be counted as guesses. Once a valid letter is entered (based on the restrictions described in step 4), your program updates the list of letters still left to try by removing this letter from the list (again refer to the sample outputs), reduces the number of guesses left by one, and checks whether the letter is part of the word to guess. If it is, then replaced the dash (or star) with the letter in the appropriate position. Step 3 to 6 are repeated until the guessing player finds all of the letter in the word or reaches 10 guesses. You program ends with a summary of the game(Against see sample outputs).

Explanation / Answer

please rate - thanks

see my message

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define MAX_GUESSES 10
string get_word();
void print_guessed_letters(string);
bool good_guess(string,char);
void printword(string,int);
char getletter(string&);
int main()
{
int i,count,used=0,guesses=0,good,found=0;
string word;
string word_so_far;
string lettersUsed="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char again='y',guess;
cout<<"Hangman ";
word=get_word();
used=0;
guesses=MAX_GUESSES;
found=0;
for(i=0;i<word.length();i++)
     word_so_far=word_so_far+'-';
word_so_far=word_so_far+'';   

while(guesses>0 &&found<word.length())
    {printword(word_so_far,guesses);
          print_guessed_letters(lettersUsed);            
    guess=getletter(lettersUsed);
    if(good_guess(word,guess))
         { for(i=0;i<word.length();i++)
              if(toupper(word[i])==guess)
                  {word_so_far[i]=word[i];
                  found++;
                  }
         }
      guesses--;
     }

if(found==word.length())
     cout<<" YOU WON!! :) :) you guessed the mystery word "<<"""<<word<<"""
                  <<" in "<<MAX_GUESSES-guesses<<" guesses ";
else
    cout<<" sorry :( :( The word was "<<word<<endl<<endl;   
cout<<"Hope you had fun! BYE for now ";
system("pause");
}
string get_word()
{string word;
cout<<"OK Guessing Player...turn around, while your friend enters the word to guess ";
cout<<"Other Player...(letters only, no repeated letters and not case sensitive ";
cin>>word;
for(int i=0;i<30;i++)
      cout<<endl;
return word;
}
char getletter(string& l)
{char letter;
bool good;
do
{good=true;
cout<<"Which letter should I check for? ";
cin>>letter;
letter=toupper(letter);
if(letter<'A'||letter>'Z')
     good=false;
else if(l[letter-'A']=='-')
     good=false;
if(!good)
    cout<<"->Not a valid request-either not a letter or already guessed ";
}while(!good);
l[letter-'A']='-';
return letter;
}
void printword(string w,int g)
{int i;
cout<<" Word to date: ";
cout<<w<<"("<<g<<" guess(es) left) ";

}
bool good_guess(string w,char let)
{int i;
for(i=0;i<w.length();i++)
      if(let==toupper(w[i]))
         return true;
      
return false;
}
void print_guessed_letters(string letters)
{int i;
cout<<"Letters not tried yet: ";
cout<<letters<<endl;
}