Select Page

That Generate Random Roll of A Pair of Dice 1000 Times and Print out A Table Exercise

Question Description

Write a C program that generate random roll of a pair of dice 1000 times and print out a table showing how many times the sum 2 was rolled, 3 was rolled, etc… up to 12. You will implement the random number generator based on the following formula:

s_new = m * s_old + n

and then setting s_old = s_new. Let m = 32310901 and n = 1729.

Prompt the user for the value of s_old.

Then map the random number s_new to a number between 1 to 6 for each of the two dice.

0. Create an array of 13 integers

1. Get the user input value s_old

2. Calculate s_new

3. Map s_new to a number between 1 to 6 for the first die. You can do this using the following formula: s_new % 6 + 1

4. Set s_old = s_new

5. Repeat steps 2-3 to get the value of the second die

6. Add the value of the two dice and store the sum into the array

7. Repeat steps 2 through 6 a total of 1000 times, making sure to save each sum into the array.

8. print the table showing the frequency of occurence of the sum 2 through 12

Ex: Your output should look something like this

>> input the value of s_old: 20

The frequency counts are:

Sum of the dice Number of Occurences

2 50

3 60

4 95

5 120

6 200

7 300

8

9

10 ETC…

11

12

Your program should contain at a minimum the following functions:

main.c // declare an array: int sum[13] make sure you initialize each value of the array to 0

int get_sold(); // get the value of s_old from the user

int generate_random(s_old); // use the formula to generate s_new given s_old Remember the output of the function becomes s_old

// on the next call

int roll_die(s_new); // map the value of s_new to a number from 1 to 6 and return it

// You will need to call generate_random and roll_die twice to get the numbers for the two dice

// Put the function calls in a for-loop that runs 1000 times and store the sum of the two dice into the array sum.

print_table(sum);

Use: sum[12] to store the number of times the sum 12 comes up

sum[11] to store the number of times the sum 11 comes up

sum[10] to store the number of times the sum 10 comes up

etc…

sum[2] to store the number of times the sum 2 comes up

sum[1] should be 0

sum[0] should be 0

Please upload all your .C files and screenshot of your outputs.

HINT:

Your main function should look something like this:

#define NTIMES 1000

#define SUMS 13

int main()

{

int sum[SUMS];

int s_old, s_new, temp_sum;

// initialize sum

for (int i = 0; i < SUMS; i++)

{

sum[i] = 0;

}

s_old = get_sold();

for (int i = 0; i < NTIMES; i++)

{

s_new = generate_random(s_old);

temp_sum = roll_die(s_new); // roll first die

s_old = s_new;

s_new = generate_random(s_old); // generate new random number

temp_sum = temp_sum + roll_die(s_new); // roll second die and add the die value to the value of the first die

sum[temp_sum] = sum[temp_sum] + 1; // increase the number of times the sum “temp_sum” was rolled

s_old = s_new;

}

return 0;

}

Your job is now to write the functions. Don’t forget to prototype the functions.

"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you "A" results."

Order Solution Now