Question
Lab6B: Pick a number between 1 and 1000 For this lab, make sureto please use a while loop. Many programming languages have alibrary for a
Lab6B: Pick a number between 1 and 1000 For this lab, make sureto please use a while loop. Many programming languages have alibrary for a Random Number Generator (RNG). Whenever this RNG isused it will output one “random” number back to the user.Applications of such a generator can including something like thelottery.
Please keep in mind that the RNG will generate a randomfloating-point value between 0.0 and 1.0 and to adjust the range ofthe random numbers you need to either multiply or add to theresult. For example, if want the range to be from 0.0 to 50.0 wewould multiply the result by 50. If wanted to move the range to 2.0to 52.0 we would add 2 to the result. Re-read this passage and tryto think about this a bit more deeply, it will click and makesense.
In this lab exercise, please write a program that asks the userto pick an integer number between 1 and 1000; please use a whileloop to verify that what was entered by the user is between therange specified earlier. If the input is within range, please havean RNG (please ask your lab instructor for details on how to createone some details shown below) that should keep randomly generatingnumbers until it generates one matching the number entered by theuser.
Also, please make sure that the program keeps track of how manyguesses it takes. Have the program displays each guess and afterthan display the total guess count. Please refer to the sampleoutput below.
Disclaimer: When using the RNG you are going to have to storethe generated number as a double or a float. Please make sure toround up the generated number to the nearest ones digit in order toavoid an infinite loop.
Remember, the class name should be Lab6B.
The user input is indicated in bold.
Java import java.util.Random; public class generateRandom{public static void main(String args[]) { Random rand = newRandom(); // Generate random integers in range 0 to 9 int rand_int1= rand.nextInt(10);} }
C# public class generateRandom{ public static void main(Stringargs[]) { Random rnd = new Random(); // Generate random integers inrange 0 to 9 int example = rnd.Next(10); } } Page 4 of 6
C++ #include #include #include using namespace std; int main() {srand((unsigned) time(0)); int randomNumber; // Generate randomintegers in range 0 to 9 randomNumber = (rand() % 10); cout<< randomNumber << endl; }
Sample output: Enter a number between 1 and 1000: 42 My guesswas 56 My guess was 198 My guess was 239 My guess was 2 My guesswas 5 ... My guess was 920 My guess was 42 I guessed the number was42 and it only took me 231 guesses
IN C# Please
Step by Step Solution
3.29 Rating (164 Votes )
There are 3 Steps involved in it
Step: 1
using System public class Lab6B public static void Main Random rnd new Random int userInput int guess 0 int totalGuesses 0 ConsoleWriteLineEnter a num...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