Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) Simulating a dice roll (40 points) We have a six-sided dice. Since we are in a computer programming class (and for your convenience) assume

image text in transcribed

2) Simulating a dice roll (40 points) We have a six-sided dice. Since we are in a computer programming class (and for your convenience) assume that faces are marked 0 through 5. In this game of dice roll, we win if we get the number 0. Write a C program, dice.c, to ask the user the number of times to roll the dice. Output the number of wins along with the probability of winning Your program must 1. Use srandO and rand) library functions from and time) library function from to generate random numbers between 0 and 5. The function srand() is used to initialize the random number generator, time) is used to get the current time, and rand) is used to generate a random number. See textbook, Chapter 8 - page 172 "Dealing a Hand of Cards" program to learn about these functions and how to use them to get random numbers in an interval. 2. Ask the user for the number of times to roll the dice, assume that the input will be greater than or equal to 3. Output the number of wins along with the probability of winning up to 3 decimal places. Example executions: You may see a different output than shown below depending upon your random number generator. You may know from your math classes that the theoretical probability of winning in this game is 1/6 or 0.166667. You will see that as you increase the number of times you roll the dice, you will get closer to this theoretical value. This is the famous "law of large numbers" in probabilitv $ gcc -Wall -o dice dice.c $ ./dice How many times to roll? 10 You won 2 out of 10 times. Your probability of winning is 0.200 $ ./dice How many times to roll? 10000 You won 1627 out of 10000 times. Your probability of winning is 0.163. EXTRA CREDIT (10 points) Extend the above program, dice.c, to input the number of sides in the dice from the user (assume that this input will be greater than 1). Name you file ndice.c. Example executions: $ gcc -Wall -o ndice ndice.c $ .dice How many faces does dice have? 5 How many times to ro11? 100 You won 21 out of 100 times. Your probability of winning is 0.210

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

15-5 How will MIS help my career?

Answered: 1 week ago