Threesuns

Email

Contact

All Semesters

Semesters

All Courses

Courses

C Language

CSCI2473

3 credits

Labs

Dice Roller

Lab

100 points

Requirements

Program compiles and runs with no errors or warnings10
Program allows input of sides and provides correct error checking of the input15
Program correctly calculates and displays the possible totals25
Program correctly calculates and displays the calculated odds for each total25
Program correctly calculates and displays the actual roll total percentages25
Total100 pts

Objective

To practice using arrays

Instructions

Overview

For this lab you will create a C program that will display all of the possible totals that can be rolled using two dice of a specified number of sides, the odds of rolling each of those totals, the actual percentage of time that each total was rolled after 36,000 attempts.

Inputs

For this lab the dice that are rolled will have a number of sides specified by the user. Prompt the user for the number of sides for this dice and accept any integer value between 2 and 100 inclusively.

Processing

With the number of sides from the user determine all of the possible totals that can be rolled using two dice with that number of sides. For example, two 6 sided dice could produce totals between 2 and 12.

Next, calculate the odds of rolling each of those totals as a percentage. Dice should not actually be rolled to find these odds.

Finally, roll two simulated dice 36,000 times and track how often each total is actually rolled. Calculate the actual percentage of each total for later display.

We can simulate rolling dice in C by using a random number generator, see attached program for an example of doing this.

Output

The program should produce 3 columns of output, see attached file for an example. The possible totals should be displayed to the user as a first column of output, the calculated odds of rolling each total should be displayed as a second column of output, and the actual percentage of times each total was rolled should be shown as the third column of output.

Summary

If C's random number generator is producing good pseudo-random numbers there should be a strong similarity between the calculated odds of rolling each total and the actual number of times each total was rolled.

Extras