in c++ need two file .cpp Also do: #include DICE ROLLING SIMULATION (20 pts): This program should simulate th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

in c++ need two file .cpp Also do: #include DICE ROLLING SIMULATION (20 pts): This program should simulate th

Post by answerhappygod »

in c++
need two file .cpp Also do: #include <stdlib.h>
DICE ROLLING SIMULATION (20 pts): This program shouldsimulate the roll of a single die (dice) (1-6) using the C++ randomnumber functions. First ask the user if they want to set the randomseed to 7 or the time of day (the random values will be different).Use the following code:
char ch;
srand(time(NULL));
cout << "Use value 7 as a random seed (y/n)? ";
cin >> ch;
if (ch == 'y' || ch == 'Y')
srand(7);
Then ask how many times they would like to have the die (dice)rolled. Next, have the program simulate the number of rolls of thedie (dice) the user requested and keep track of which number thedie (dice) landed on for each roll – use a switch statement andnot
ifs. At the end of the program print out a report showing howmany times the die (dice) roll landed on each number and whatpercentage of the total times the die (dice) roll landed on eachnumber. Do NOT use functions or arrays on this - use what I showedyou during lecture, you should always listen during lecture to getthe right techniques, if you forgot what I said during lecture lookat the slides.
Input Validation: Do not allow the user to enter a number lessthan 1 as the number of times they would like to roll the dice. Usea do/while loop for the input validation. Your output should looksimilar to what is below:
In this example, the user entered n for “time-of-day” seed then25 as the number of times they would like to roll the dice.
Use value 7 as a random seed (y/n)? n
Please enter in number of rolls: 0
Please enter rolls > 1
Please enter in number of rolls: 25
DICE ROLL STATISTICS
# Rolled # Times % Times
-------- ------- -------
1 4 16.00%
2 3 12.00%
3 5 20.00%
4 7 28.00%
5 4 16.00%
6 2 8.00%
HINT: Put your srand() function outside of your loop (otherwiseyou reset the random sequence every time – not too random!) likeshown above. Watch what happens if you put it inside loop and seeif you can figure out why that happens.
Also do: #include <stdlib.h>
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply