#include using namespace std; #include "dice.h" #include "prompt.h" #include "tvector.h" // use vector to simulate rolling of two dice // Owen Astrachan, March 9, 1994, modified 5/2/99 const int DICE_SIDES = 4; int main() { int sum; int k; Dice d(DICE_SIDES); tvector diceStats(2*DICE_SIDES+1); // room for largest dice sum int rollCount = PromptRange("how many rolls",1,20000); for(k=2; k <= 2*DICE_SIDES; k++) // initialize counters to zero { diceStats[k] = 0; } for(k=0; k < rollCount; k++) // simulate all the rolls { sum = d.Roll() + d.Roll(); diceStats[sum]++; } cout << "roll\t\t# of occurrences" << endl; for(k=2; k <= 2*DICE_SIDES; k++) { cout << k << "\t\t" << diceStats[k] << endl; } return 0; }