Project 4 - Rolling Dice

Due: Wednesday, May 17, 2000 BY 11:00 AM
       (extended from Monday, May 15)


Objectives:

Your program will simulate the rolling of a pair of dice for as many times as the user wishes. You will keep track of how many times a particular value is rolled, by having an array of counters. The possible values will be 2 through 12.

Some Interesting Background

The value 2, also known as snake eyes, can only be produced when each of the two dice have come up 1's. Likewise, the value 12, also known as boxcars, can only be produced when each of the two dice have come up with the value 6. The other values (the values between 3 and 11) will tend to occur more often than either the snake eyes or the boxcars, because there is more than one roll possible to create those values. The 3 could be gotten by die #1 rolling a 1, and die #2 rolling a 2 OR by die #1 rolling a 2 and die #2 rolling a 1. So theoretically, it is twice as likely that a 3 will be rolled, rather than a 2 or a 12. Other values rolled will exhibit other probabilities.

The Project

The basic project is to simply simulate the rolling of two dice and counting how many times each of the possible values was rolled. The counts are to be stored in an array. After all of the rolling is complete, you must print a report that shows each of the possible values and the number of times it was rolled. DO NOT STORE THE INDIVIDUAL VALUES ROLLED IN AN ARRAY. Your book can really help you out with this project, since it gives an example of a similar program. You are rolling two dice, rather than one...AND...you MUST have at least one function that takes an array as an argument.

You should do most of your work in functions. I would suggest that you write a function called RollDice, which would return the result of rolling 2 dice. (The sum of two individual die rolls). You should also have a function that will print the report of the number of rolls that occurred for each possible value. A good design will have other functions as well. Your output MUST be formatted EXACTLY as shown below. So make sure that the values and number of occurrences line up in columns. Also remember to seed the random number generator using time() before beginning to draw random numbers.

Give your program source code file the name proj4.c. E-mail this file to Evelyn (cwang3@cs.umbc.edu). Do NOT send your executable file (a.out).


Sample Output

The dice were rolled 57 times. 2 was rolled 1 time(s) 3 was rolled 2 time(s) 4 was rolled 5 time(s) 5 was rolled 6 time(s) 6 was rolled 15 time(s) 7 was rolled 12 time(s) 8 was rolled 8 time(s) 9 was rolled 4 time(s) 10 was rolled 2 time(s) 11 was rolled 2 time(s) 12 was rolled 0 time(s)