//----------------------------------------------------------------------
//  rolldice.cpp
//  This program investigates the odds for rolling pairs
//  of dice by randomly generating such rolls.
//----------------------------------------------------------------------
#include <iostream.h>
#include <iomanip.h>    // For setw()
#include "rand.h"

int main()
{
    int  totalRolls;
    int  i;
    int  currentRoll;
    int  rollCount[13];    // Only elements 2..12 will be used
    int  die1;
    int  die2;
    long initialSeed;

    cout << "Specify total number of dice rolls: ";
    cin >> totalRolls;
    cout << "\nSpecify an initial seed (positive integer): ";
    cin >> initialSeed;
    SetSeed( initialSeed );

    for (i = 2; i <= 12; i++)  // INV (prior to test):
                               //   All rollCount[2..i-1]==0  &&  i<=13
        rollCount[i] = 0;

    for (currentRoll = 1; currentRoll <= totalRolls; currentRoll++) {
                          // INV (prior to test):
                          //     For 2<=k<=12, rollCount[k] == count of
                          //        all dice rolls totaling k out of the
                          //        first currentRoll-1 rolls
                          //  && currentRoll <= totalRolls+1
        die1 = int( NextRand()*6.0 ) + 1;
        die2 = int( NextRand()*6.0 ) + 1;
        rollCount[die1+die2]++;
    }

    cout << "\nTotal number of simulated dice rolls: "
         << totalRolls << '\n';

    for (i = 2; i <= 12; i++)   // INV (prior to test):
                                //     rollCount[2..i-1] have been output
                                //  && i <= 13
        cout << "    Roll: " << setw(2) << i
             << "   Occurrences:" << setw(5) << rollCount[i] << '\n';

    return 0;
}

