Topical Information

This lab should help you with the concept of simple branching combined with fancy input while continuing to let you practice with random value generation.

Program Information

Returning to the dice roll statistics program, you realize that many dice rolls in games require not just a simple roll and addition of the faces' dots. Some games adjust the score thusly achieved by adding or subtracting a set amount from the dot-total. Such rolls are designated by 'NdSaA': roll N dice of size S and adjust the total by A.

For instance, you might be told to roll 2d6+3. This would give values between 5 and 15 (inclusive). (The 2d6 gives 2 to 12 and adding 3 to each value in this range gives 5 to 15.) The new formulas for this adjusted dice roll are:

   min = N+A

   max = N*S+A

          min+max
   avg = ---------
             2

Hmm...the last one seems familiar...*grin*

Note, though, that the adjustment may be a positive value, a negative value, or even 0. When the adjustment is 0, the user may even leave it off of their input completely! Some sample rolls:

    2d6            2d6-2              2d6+3
    1d4+1          3d12-6             5d8+0

Notice in the above samples that the last one specifies a 0 adjustment but the first one simply left off the adjustment!

Calculate the three statistics for the user's adjusted dice roll and report them in a nice way. You should also give them a sample roll value (what might possibly) come up during an actual roll.


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

$ adjdicestat.out

                 Welcome to the Dice Statistics Program!!!

Enter your dice roll:  3d12+2

Thank you!!  Calculating...  Done.

When rolling 3 size-12 dice adjusted by +2, your statistics will be:

   Minimum:  5
   Average:  21.5
   Maximum:  38

A typical dice roll might result in 13.

Thank you for using the DSP!!

Endeavor to have a tumbling day!

$

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


Thought Provoking Questions

  1. How can you let the user give an optional ending part to their input (like the 0-adjusted rolls)? (Hint: perhaps the peek function might have something to do with it?) (Hint: are you deciding whether to read the adjustment or not?)
  2. How can you decide to print a + sign in front of an adjustment value when labeling the output? (See the above sample run...)
  3. How has the adjustment 'factor' affected the statistics formulas? In particular, why is the average formula unchanged?
  4. Why is the stat formula for the min and max just '+A' when A could be positive or negative or even zero? Shouldn't it be a 'plus or minus' sign (±)?

This assignment is (Level 3.5).


Options


Total Level Possible

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