Question
Exercise 2: Word game Create a new program, WordGuessingGame . Using a while loop, create a game for the user. The game requires the user
Exercise 2: Word game
Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis. With each guess...
If the guess does not have an equal number of characters, tell the user if it is too long or too short
If the guess has the same number of characters, tell the user how many characters are correct
The letter must be in the same position to be considered correct.
This is how its supposed to work:
Welcome to the word guessing game. Guess a word: borp The word is longer Incorrect. Guess again: turtle The word is longer Incorrect. Guess again: cowabungazzzz The word is shorter Incorrect. Guess again: Xalenbine You have 7 letters correct Incorrect. Guess again: VALENTINE You have 0 letters correct Incorrect. Guess again: enitnelav You have 1 letters correct Incorrect. Guess again: valentine You win! Would you like to play again? (y/n): n
----------------------------------------------------------------------------------------------------------------------------------------
This is how far i got. I couldnt figure out the rest. Thanks for any help.
#include
int main() { char quit ='\0' std::string tobeguessed; tobeguessed = "valentine"; std::string guess =""
while(quit !=n) { while(1) { std :: cout << "Welcome to the word guessing game. "; std :: cin >> guess; if(guess.length() < tobeguessed.length()) { std :: cout << "The word is longer " << "Incorrect. Guess again: "; } else if(guess.length() > tobeguessed.length()) { std :: cout << " The word is shorter " << "Incorrect. Guess again: "; } else if(guess.length() == tobeguessed.length()) { if(guess==tobeguessed) { std :: cout << "You win! "; break; } else { for(guess; guess == tobeguessed; guess++) { if( { } {
} }
}//inner loop(plays game) std :: cout << "Would you like to play again? (y/n): "; std :: cin >> quit; }//outer loop return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started