Having a problem with my code for an assignment i'm doing,it's hangman.When I get the input from the user i want to check to see if it is in the secret word.I think i'm on the right track.any suggestions????
Code:#include <iostream> #include <cstdlib> #include <string> using namespace std; int main() { int lives; int num; int strsize ; string word_to_guess; string wordguessed; string words [10] = {"Dell","School","Phone","Water","Book","Computer","Window","Matches","Television","Bed"}; string lettersguessed; string guess; cout<<"\n\t\t *********** H A N G M A N ***********\n\n"; cout<<"\n\t\t Welcome to To the game of Hangman \n\n"; cout<<"\n\t\t Guess the letters of the random word \n\n"; srand((unsigned)time(NULL)); num = rand() % 9 + 0; word_to_guess = words[num]; strsize = word_to_guess.size(); lives = word_to_guess.size(); lives = lives + 2; cout<<"Guess the secret word it has "<<strsize <<" letters and you guess one letter at a time "<<endl<<endl; wordguessed = word_to_guess; for(int i = 0; i<word_to_guess.size();i++) { word_to_guess[i] = 'X'; } cout<<word_to_guess<<endl<<endl; while (lives>0 && wordguessed!=word_to_guess) { cout<<"You have "<<lives<<" guesses left"<<endl<<endl; cout<<"Please enter your guess"<<endl<<endl; cin>>guess; lives = lives -1; lettersguessed = lettersguessed + guess; for (int i=0; i=word_to_guess.size();i++) { word_to_guess[i] = guess; } cout<<word_to_guess; cout<<"Your letters "<<lettersguessed<<endl<<endl;



LinkBack URL
About LinkBacks


