Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses a function that returns a number between 1 and 6. Use this function to simulate the roll of a die.

Write a program that uses a function that returns a number between 1 and 6. Use this function to simulate the roll of a die. Allow the user to specify the number of trials and then tabulate that number of rolls of two dice. The program must allow for repeated simulations. Initialize rand() using srand() and time(). (in C++) Possible Outcomes for any roll 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36 41 42 43 44 45 46 51 52 53 54 55 56 61 62 63 64 65 66 Possible Totals 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12 Therefore, for example, the odds of a 7 are 6:36 in any given roll. If you roll 36 times then the expected outcome for a 7 is 6. So odds are that you will get a 7, 6 times. The odds you will get a 2 are 1. Tabulate the difference between the expected outcome (odds) and the random number generator outcome list this as error. In general, you should notice a decrease in error with more trials.

Please enter the number of rolls you want: 36 Sum #Rolled Odds %Error 2: 0 1 100.0000 3: 1 2 50.0000 4: 1 3 66.6667 5: 7 4 75.0000 6: 6 5 20.0000 7: 5 6 16.6667 8: 2 5 60.0000 9: 9 4 125.0000 10: 6 3 100.0000 11: 0 2 100.0000 12: 0 1 100.0000 Try again? (1 = Yes, 0 = Exit) 1 Please enter the number of rolls you want: 360 Sum #Rolled Odds %Error 2: 5 10 50.0000 3: 19 20 5.0000 4: 24 30 20.0000 5: 40 40 0.0000 6: 64 50 28.0000 7: 54 60 10.0000

8: 62 50 24.0000 9: 32 40 20.0000 10: 34 30 13.3333 11: 17 20 15.0000 12: 10 10 0.0000 Try again? (1 = Yes, 0 = Exit) 1 Please enter the number of rolls you want: 36000 Sum #Rolled Odds %Error 2: 1007 1000 0.7000 3: 2037 2000 1.8500 4: 3015 3000 0.5000 5: 3970 4000 0.7500 6: 4964 5000 0.7200 7: 6030 6000 0.5000 8: 4977 5000 0.4600 9: 3959 4000 1.0250 10: 3041 3000 1.3667 11: 2008 2000 0.4000 12: 993 1000 0.7000 Try again? (1 = Yes, 0 = Exit) 1 Please enter the number of rolls you want: 36000000 Sum #Rolled Odds %Error 2: 1000809 1000000 0.0809 3: 2002943 2000000 0.1472 4: 3003377 3000000 0.1126 5: 3998148 4000000 0.0463 6: 4998322 5000000 0.0336 7: 5999486 6000000 0.0086 8: 4999017 5000000 0.0197 9: 3997214 4000000 0.0697 10: 3001276 3000000 0.0425 11: 1998918 2000000 0.0541 12: 1000491 1000000 0.0491 Try again? (1 = Yes, 0 = Exit) 1 Please enter the number of rolls you want: 360000000 Sum #Rolled Odds %Error 2: 10008663 10000000 0.0866 3: 19995846 20000000 0.0208 4: 30002587 30000000 0.0086 5: 39991880 40000000 0.0203 6: 50008270 50000000 0.0165 7: 59998415 60000000 0.0026 8: 50008624 50000000 0.0172 9: 39989290 40000000 0.0268 10: 30003247 30000000 0.0108 11: 19991608 20000000 0.0420 12: 10001571 10000000 0.0157 Try again? (1 = Yes, 0 = Exit)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899