Topical Information

This lab should help you with the concept of random value generation. It also provides more practice with calling library functions.

Program Information

Write a program that helps the user determine the statistics on a common dice roll. To refresh your memory, you normally pick a size of die and a number of dice to roll. Normally gamers term this NdS, where N is the number of dice and S is the size of each of the die (so 4 12-sided dice would be 4d12).

The minimum value achievable on such a roll is N (since each die has a minimum value of 1 and there are N of them). The maximum value you can get on such a roll is N*S (since the maximum value on each die is S and there are N of them). The average of such a roll is the quantity:

   minimum + maximum
  -------------------
           2

Believe it or not!

Your program needs to calculate these three statistics for the user and report them in a nice way. It would also be nice to give them a sample roll value (i.e. what might possibly come up during an actual roll).


As an example, you might have the program interaction look something like (the parts typed like this are what the user typed):

$ dicestat.out

                 Welcome to the Dice Statistics Program!!!

How many dice in your dice roll?  3
How many sides on the dice in your dice roll?  12

Thank you!!  Calculating...  Done.

When rolling 3 size-12 dice, your statistics will be:

   Minimum:  3
   Average:  19.5
   Maximum:  36

A typical dice roll might result in 23.

Thank you for using the DSP!!

Endeavor to have an extemporaneous day!

$

Note how the average is a decimal value even though there is no possible way to roll a 19.5 on a standard die. (That's statistics for ya'!)


Thought Provoking Questions

  1. If you fail to call the srand function, every run of your program with the same kind of dice roll results in the same typical roll value. Why is this?
  2. Why do we nest the call to the time function inside the call to the srand function? What is that funny argument to the time function (not its meaning, but just what is it)?
  3. Explain how the formula derived in the notes works to generate numbers in a specified range.
  4. Bonus: Can you verify the simple formula I gave for the average value of a dice roll? (Hint: Use a small die like a 4-sider and try rolling different numbers of them. What possible values are there for each die? What possible sums can result? How many ways can each sum occur? What is this as a fraction of the total number of possible die combinations?)

This assignment is (Level 2).


Options


Total Level Possible

If you did all above options, this lab could be worth as much as (Level 5).