header

Homework 25

Write a program that simulates 1000 rolls of a pair of dice and summarizes the results in a table.

Output Specifications

The results are to be displayed in a table formatted as shown below where ### indicates an integer value displayed in a field three characters wide.

Dot Sum   Frequency
-------   ---------
    2        ###
    3        ###
    4        ###
    5        ###
    6        ###
    7        ###
    8        ###
    9        ###
   10        ###
   11        ###
   12        ###

Input Specifications

None. This program has no input.

Process Specifications

Your program should include a value-returning function that returns a random integer value in the range 1 to 6 inclusive. For each roll of a pair of dice, you need to invoke this function twice and add the results (the dot sum is the sum of the dots showing on the two dice) Your main program should simulate 1,000 rolls of a pair of dice and count how many times you get a dot sum of 2, how many times you get a dot sum of 3, and so on.

C++ includes a function named rand( ) that returns random numbers in the range 0 to RAND_MAX (inclusive). RAND_MAX is usually the same as INT_MAX (the largest possible integer value). Random numbers in the range 0 to n-1 inclusive can be generated using this expression:

rand()%n

For example, to generate one of 6 random values in the range 0 to 5 inclusive, use this expression:

rand()%6