UMBC CMSC 104 Spring 2000 CSEE | 104 | current 104

Programming Project # 4

Rolling Dice

Due: Monday, May 15, 2000 before midnight


This project is designed to give you experience working with arrays, passing arrays to functions, and using the pseudo-random number generator.

Your program will simulate the rolling of a pair of dice for as many times as the user wishes, up to 30,000 times. 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. The value 2, aka snake eyes, can only be produced when each of the two dice have come up 1's. Likewise, the value 12, aka 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 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 should be formatted so that the values and number of occurrences line up in columns as shown below. You must seed the random number generator using time() before beginning to draw random numbers.

Example of a report of rolls:

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)