Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming: Write a program that simulates the rolling of three dice. The program should use rand three times to roll the first die, second

C Programming:

Write a program that simulates the rolling of three dice. The program should use rand three times to roll the first die, second die and third die, respectively. The sum of the three values should then be calculated. [Note: Because each die can show and integer value from 1 to 6, then the sum of the three values will vary from 3 to 18, with 10 and 11 being the most frequent sums and 3 and 18 the least frequent sums.] Your program should roll the three dice 2,160,000 times. Use a single-subscripted array to tally the numbers of times each possible sum appears. Print the results in tabular format. Also, determine if the totals are reasonable; i.e., are there 27 ways to roll a 10, so approximately one-eighth of all the rolls should be 10.

1. Pseudocode of the main() function

Define a constant NUM_ROLL = 2160000

Define an array freq with 16 elements for the frequency counters

Initialize all the elements to 0

Repeat the following steps for NUM_ROLL iterations:

Call the function roll_three_dice() to return the sum of the face values of three rolls

Increase the corresponding array element by 1

Print the array to display the results, i.e., the frequency counts and the percentages

Stop

Note: The percentage is given by (double) freq[i] / (double) NUM_ROLL

2. Pseudocode of the function roll_three_dice

It takes no parameters and returns the sum of the face values of three rolls. Its header is

unsigned int roll_three_dice(void)

Pseudocode:

Get the face value from rolling the 1st die by using rand() % 6 + 1

Get the face value from rolling the 2nd die by using rand() % 6 + 1 again

Get the face value from rolling the 3rd die by using rand() % 6 + 1 again

Return the sum of the three face values

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

ISBN: 0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

solve each system of equation below by graphing \f

Answered: 1 week ago

Question

Describe the typical collective bargaining process.

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago