/* This program simulates a given number of pairs of dice rolls,
   and counts the number of times a specified number occurs.

   Input:  Number of dice rolls, the number to be counted,
           and user's response to "More rolls?" query
   Output: User prompts, and the relative frequency of
           the number of spots
------------------------------------------------------------------*/

#include <iostream.h>

#include "RandomInt.h"

int main(void)
{
   cout
      << "This program simulates a given number of dice-pair rolls,\n"
      << "\tcounting the number of times a given number occurs.\n";

   int
      NumRolls;                         // number of rolls of dice

   cout << "\nHow many times are the dice to be rolled ? ";
   cin >> NumRolls;

   RandomInt
      Die1(1, 6),                       // the first die
      Die2(1, 6);                       // the second die

   int
      Pair,                             // the sum of the dice
      NumberBeingCounted,               // the number we want to count
      Occurrences;                      // the counter variable

   char
      Response;                         // user's query response

   do                                   // repeat the following:
   {                                    //   get outcome to count
      cout << "\nWhich number do you want counted (2-12)? ";
      cin >> NumberBeingCounted;

      Occurrences = 0;                  //   set counter to zero

                                        //   for loop to repeat
      for (int RollCount = 1;           //    the following
           RollCount <= NumRolls;       //    NumRolls times:
           RollCount++)
      {                                 //      roll the dice
         Pair = Die1.Generate() + Die2.Generate();

         if (Pair == NumberBeingCounted)
            Occurrences++;              //      increment the counter
      }                                 //   end for loop

                                        //   display the result
      cout << "\nThe relative frequency of " << NumberBeingCounted
           << " was " << double(Occurrences) / double(NumRolls)
           << "\n\n";
                                         //   query the user
      cout << "Do you want to do another (y or n) ? ";
      cin >> Response;
   }                                     // until ready to quit
   while ((Response == 'y') || (Response == 'Y'));

   return 0;
}

