rendered paste body/* Dice Rolls program */
#include <iostream.h>
#include <lvp\vector.h>
#include <lvp\random.h>
typedef vector<int> CountType;
//--------------------------------------------------------------------------------
void DisplayCounts(const CountType &Count)
/* Displays the contents of Count[2] through Count[12] in two columns
Post: Contents of Count displayed */
{
cout << "Roll" << " " << "Count" << endl;
for (int Roll=2; Roll<=12; Roll++) {
cout << Roll << " " << Count[Roll] << endl;
}
}
//--------------------------------------------------------------------------------
void CountTrials(CountType &Count, int NumTrials)
/* Simulates NumTrials rolls of two dice and stores the counts of each
outcome in Count
Post: NumTrials dice rolls simulated. Count of outcomes of NumTrial
simulated rolls stored in Count */
{
for (int Trial=1; Trial<=NumTrials; Trial++) {
int Roll = (random(6) + 1) + (random(6) + 1);
Count[Roll]++;
}
}
//--------------------------------------------------------------------------------
int main()
{
randomize();
CountType Count(13, 0); // Array with indexes 0 through 12,
// each element initialized to 0
const int NumTrials = 1000;
CountTrials(Count, NumTrials);
DisplayCounts(Count);
return(0);
}