Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file.

please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file. (on separate lines) Write the number of guesses to the file at the end of the game. After the game is finished, ask the user if they want to play again. If 'n' or 'N' don't play again, otherwise play again! NOTE: your file should have more than one game in it if the user plays more than one game. Don't forget - pseudocode, comments, proof of testing. Post file(s) in digication, then post link on MOODLE. SLOs: code modification file writing looping algorithm modification*/ #include #include //for rand and srand #include //for the time function using namespace std; int main() { srand(time(0)); // Seed the random number generator srand(NULL); //asking user if he/she likes to play a game cout << "Would you like to play a game? "; char ch; // choices cin >> ch; // if choice is 'Y' or 'y' if (ch == 'Y' || ch == 'y') { //generating a random number between 1 and 10 int randNum = (rand() % 10) + 1; int guess; //asking and reading a guess cout << "Guess a number between 1 and 10: "; cin >> guess; //if guess is same as number, if (guess == randNum) { cout << "Bingo" << endl; } //if guess is smaller than number, else if (guess < randNum) { cout << "too low" << endl; } //if guess is bigger than number, else { cout << "too high" << endl; } } 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

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago