Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!