9-11 shows the completed guessing game program and includes a sample run of the m. The statement on Line 15 uses the srand and time functions to initialize the random er generator. The rand function, which appears in the assignment statement on Line 16, res a random integer from 1 through 10. The statement assigns the random integer to the Number variable.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please provide full completed code

Figure 9-11 shows the completed guessing game program and includes a sample run of the
gram. The statement on Line 15 uses the srand and time functions to initialize the random
number generator. The rand function, which appears in the assignment statement on Line 16,
generates a random integer from 1 through 10. The statement assigns the random integer to the
randomNumber variable.
Transcribed Image Text:Figure 9-11 shows the completed guessing game program and includes a sample run of the gram. The statement on Line 15 uses the srand and time functions to initialize the random number generator. The rand function, which appears in the assignment statement on Line 16, generates a random integer from 1 through 10. The statement assigns the random integer to the randomNumber variable.
1 7/Guessing Game.cpp - number guessing game
2 7/Created/revised by <your name> on <current date>
3
4 #include <iostream>
5 #include <ctime>
6 //#include <cstdlib>
7 using namespace std;
8
9 int main()
10 {
required for the
time function
your compiler may require
this directive to use the
rand and srand functions
11
12 int numberGuess 0;
13
14
int randomNumber - 0;
15
16
17
//generate a random number from 1 through 10
srand (static cast<int>(time (0)));
randomNumber - 1 + rand() % (10 - 1 + 1);
18 //get first guess from user
19
20
21
22 while (numberGuess !- randomNumber)
23
24
25
26
27
28
cout <« "Guess a number from 1 through 10: ";
cin >> numberGuess;
{
cout <« "Sorry, guess again: ";
cin >> numberGuess;
} //end while
cout « endl « "Yes, the number is "
« randomNumber <<
« endl;
29
30
31 } //end of main function
return 0;
E Guessing Game
Guess a number from 1 through 10: 5
Sorry, guess again: 8
Sorry, guess again: 2
Yes, the number is 2.
Press any key to continue
Figure 9-11
Guessing game program
Transcribed Image Text:1 7/Guessing Game.cpp - number guessing game 2 7/Created/revised by <your name> on <current date> 3 4 #include <iostream> 5 #include <ctime> 6 //#include <cstdlib> 7 using namespace std; 8 9 int main() 10 { required for the time function your compiler may require this directive to use the rand and srand functions 11 12 int numberGuess 0; 13 14 int randomNumber - 0; 15 16 17 //generate a random number from 1 through 10 srand (static cast<int>(time (0))); randomNumber - 1 + rand() % (10 - 1 + 1); 18 //get first guess from user 19 20 21 22 while (numberGuess !- randomNumber) 23 24 25 26 27 28 cout <« "Guess a number from 1 through 10: "; cin >> numberGuess; { cout <« "Sorry, guess again: "; cin >> numberGuess; } //end while cout « endl « "Yes, the number is " « randomNumber << « endl; 29 30 31 } //end of main function return 0; E Guessing Game Guess a number from 1 through 10: 5 Sorry, guess again: 8 Sorry, guess again: 2 Yes, the number is 2. Press any key to continue Figure 9-11 Guessing game program
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education