Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ I want to make number matching game. Conditions are these : 1. Excellent! You guessed the number! Would you like to play again

In c++ I want to make number matching game.

Conditions are these

:

1. Excellent! You guessed the number!

Would you like to play again (y or n)?

2. Too low. Try again.

3. Too high. Try again.

// Randomly generate numbers between 1 and 1000 for user to guess. #include #include #include using namespace std; void guessGame(); // function prototype int isCorrect(int, int); // function prototype int main() { srand(time(0)); // seed random number generator guessGame(); } // end main // guessGame generates numbers between 1 and 1000 and checks user's guess void guessGame() { int answer = 0; // randomly generated number int guess = 0; // user's guess char response = 'y'; // 'y' or 'n' response to continue game // loop until user types 'n' to quit game do { // generate random number between 1 and 1000 // 1 is shift, 1000 is scaling factor answer = // 1) your codes // prompt for guess cout << "I have a number between 1 and 1000. " << "Can you guess my number? " << "Please type your first guess." << endl << "?"; cin >> guess; // check the guess and compare with answer.loop until correct number while (// 2) your codes) cin >> guess; // prompt for another game cout << " Excellent! You guessed the number! " << "Would you like to play again (y or n)? "; cin >> response; cout << endl; } while (// 3) your codes); } // end function guessGame // isCorrect returns true if g equals a // if g does not equal a, displays hint int isCorrect(int g, int a) { // guess is correct //4) your codes. Check and return 1 // guess is incorrect; display hint. Too low. Try again or Too high. Try again. //5) your codes. Check and return 0 } // end function isCorrect

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

Step: 3

blur-text-image

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 Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

1. Explain why evaluation is important.

Answered: 1 week ago