C++ #include #include #include using namespace std; int main() { srand ( (unsigned) time (0)); int randomNumber; // Generate random integers in range 0 t 9 randomNumber = (rand () % 10); cout << randomNumber « endl; } Sample output: Enter a number between 1 and 1000: 42 My guess was 56 My guess was 198 My guess was 239 My guess was 2 My guess was 5 My guess was 920 My guess was 42 I guessed the number was 42 and it only took me 231 guesses

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

in c++

Lab6B: Pick a number between 1 and 1000 For this lab, make sure to please use a while loop. Many
programming languages have a library for a Random Number Generator (RNG). Whenever this RNG is
used it will output one "random" number back to the user. Applications of such a generator can including
something like the lottery.
Please keep in mind that the RNG will generate a random floating-point value between 0.0 and 1.0 and
to adjust the range of the random numbers you need to either multiply or add to the result.
For example, if want the range to be from 0.0 to 50.0 we would multiply the result by 50. If wanted to
move the range to 2.0 to 52.0 we would add 2 to the result. Re-read this passage and try to think about
this a bit more deeply, it will click and make sense.
In this lab exercise, please write a program that asks the user to pick an integer number between 1
and 1000; please use a while loop to verify that what was entered by the user is between the
range specified earlier. If the input is within range, please have an RNG (please ask your lab
instructor for details on how to create one some details shown below) that should keep randomly
generating numbers until it generates one matching the number entered by the user.
Also, please make sure that the program keeps track of how many guesses it takes. Have the program
displays each guess and after than display the total guess coun
below.
Please refer to the sample output
Disclaimer: When using the RNG you are going to have to store the generated number as a
double or a float. Please make sure to round up the generated number to the nearest ones digit
in order to avoid an infinite loop.
Remember, the class name should be Lab6B.
The user input is indicated in bold.
Transcribed Image Text:Lab6B: Pick a number between 1 and 1000 For this lab, make sure to please use a while loop. Many programming languages have a library for a Random Number Generator (RNG). Whenever this RNG is used it will output one "random" number back to the user. Applications of such a generator can including something like the lottery. Please keep in mind that the RNG will generate a random floating-point value between 0.0 and 1.0 and to adjust the range of the random numbers you need to either multiply or add to the result. For example, if want the range to be from 0.0 to 50.0 we would multiply the result by 50. If wanted to move the range to 2.0 to 52.0 we would add 2 to the result. Re-read this passage and try to think about this a bit more deeply, it will click and make sense. In this lab exercise, please write a program that asks the user to pick an integer number between 1 and 1000; please use a while loop to verify that what was entered by the user is between the range specified earlier. If the input is within range, please have an RNG (please ask your lab instructor for details on how to create one some details shown below) that should keep randomly generating numbers until it generates one matching the number entered by the user. Also, please make sure that the program keeps track of how many guesses it takes. Have the program displays each guess and after than display the total guess coun below. Please refer to the sample output Disclaimer: When using the RNG you are going to have to store the generated number as a double or a float. Please make sure to round up the generated number to the nearest ones digit in order to avoid an infinite loop. Remember, the class name should be Lab6B. The user input is indicated in bold.
C++
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
srand ( (unsigned) time (0));
int randomNumber;
// Generate random integers in range 0 t 9
randomNumber = (rand () % 10);
cout << randomNumber « endl; }
Sample output:
Enter a number between 1 and 1000: 42
My guess was 56
My guess was 198
My guess was 239
My guess was 2
My guess was 5
My guess was 920
My guess was 42
I guessed the number was 42 and it only took me 231 guesses
Transcribed Image Text:C++ #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { srand ( (unsigned) time (0)); int randomNumber; // Generate random integers in range 0 t 9 randomNumber = (rand () % 10); cout << randomNumber « endl; } Sample output: Enter a number between 1 and 1000: 42 My guess was 56 My guess was 198 My guess was 239 My guess was 2 My guess was 5 My guess was 920 My guess was 42 I guessed the number was 42 and it only took me 231 guesses
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

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