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