Write a program that calls a method RollDie that simulates the rolling of a pair of dice 1000 times. Use an array of size 11 to keep track of the rolls. After the 1000 rolls, output a list of the Rolls (2-12) and the frequency (count out of 1000) of each roll.
#include <cstdlib> #include <ctime> using namespace std; void RollDie(int counts[]) { for (int i = 0; i < 13; ++i) { counts[i] = 0; } for (int i = 0; i < 1000; ++i) { counts[(1 + rand() % 6) + (1 + rand() % 6)]++; } } int main() { srand(time(NULL)); int counts[13]; RollDie(counts); cout << "Roll Time\tFrequency" << endl; for (int i = 2; i <= 12; ++i) { cout << i << "\t\t" << counts[i] << endl; } return 0; }
int counts[13];
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)