Question: PROGRAM #1 - DICE ROLLING SIMULATION This program should simulate the roll of a single die (dice) (1-6) using the C++ random number functions. First
PROGRAM #1 - DICE ROLLING SIMULATION This program should simulate the roll of a single die (dice) (1-6) using the C++ random number functions. First ask the user how many times they would like to have the die (dice) rolled. Next, have the program simulate the number of rolls of the die (dice) the user requested and keep track of which number the die (dice) landed on for each roll. At the end of the program print out a report showing how many times the die (dice) roll landed on each number and what percentage of the total times the die (dice) roll landed on each number. Do NOT use functions or arrays on this - use what I showed you during lecture, you should always listen during lecture to get the right techniques, if you forgot what I said during lecture look at the slides.
Input Validation: Do not allow the user to enter a number less than 1 as the number of times they would like to roll the dice. Your output should look similar to what is below (exact solution on Hypergrade "View Required Output" link):
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 (remember what happened in class when we put it inside the loop!). Watch what happens if you put it inside loop and see if you can figure out why that happens. Make sure your program does not use the same random sequence each time you run it.
IMPORTANT NOTE - READ!: The auto-grader will NOT work perfectly for this!! It has randoms, so there is no way you will be able to match this perfectly. I put up the output so you could match as closely as possible. If you try the to match the auto-grader exactly you'll be working a long time. Instead just get teh auto-grader to compile your code and match it up the best you can.
Regarding output: For the dice number and percentage of times rolled a setw(8) was used.
View required output
Test Case 1
| Standard Input |
|---|
-1ENTER 0ENTER 1 |
How many times would you like to roll the dice? This is an invalid number. The number of rolls should be equal to or greater than 1. Please enter again. This is an invalid number. The number of rolls should be equal to or greater than 1. Please enter again. DICE ROLL STATISTICS # Rolled # Times % Times -------- -------- -------- 1 0 0.00% 2 0 0.00% 3 0 0.00% 4 1 100.00% 5 0 0.00% 6 0 0.00%
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
