Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions

Question

What is the role of government in a mixed economy?

Answered: 1 week ago

Question

How autonomous should the target be left after the merger deal?

Answered: 1 week ago