#include #include // for time #include // for srand and rand using namespace std; // simulate rolling of two dice (a LOT of times) // this function will roll two dice and return result int RollDice() { int x, y; x = rand() % 6 + 1; y = rand() % 6 + 1; return x + y; // add the dice together } int main() { int number, total; srand(time(0)); // seed the random generator cout << "How many times would you like to roll the dice? "; cin >> number; // let's use an array for our COUNTERS! // sometimes called a "frequency array" int counters[13] = {0}; // so that I have slots 0-12 for (int i = 0; i < number; i++) { total = RollDice(); counters[total]++; // it's COUNTED! } cout << "Total\t\t\tFrequency\n"; cout << "----------------------------------------\n"; // print results: for (int i = 2; i < 13; i++) { cout << i << "\t\t\t" << counters[i] <<'\n'; } }