mber of times ay value for a
In addition to the instructions on the screenshot, please ensure that your program is made in C++ with comments. Please also ensure that screenshots are taken for the source code and the executed version, including all possible cases. Finally, add your code in a manner so I can just copy and paste it for review. Thanks.


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int seed;
int n;
int die;
int *frequency = new int(6); //dynamic 1D array
int min, max;
int range;
seed = time(0);
srand(seed);
for (int i=0; i<6; i++)
frequency[i] = 0;
cout << "How many dice should be rolled? ";
cin >> n;
for (int i=0; i<n; i++)
{
die = rand()%6;
switch(die)
{
case 0:
frequency[0]++;
break;
case 1:
frequency[1]++;
break;
case 2:
frequency[2]++;
break;
case 3:
frequency[3]++;
break;
case 4:
frequency[4]++;
break;
case 5:
frequency[5]++;
break;
}
}
cout << "Face\tFrequency" << endl;
for (int i=0; i<6; i++)
{
cout << i+1 << "\t" << frequency[i] << endl;
}
min = max = range = frequency[0];
for (int i=1; i<6; i++)
{
if (frequency[i] < min)
min = frequency[i];
if (frequency[i] > max)
max = frequency[i];
}
range = max - min;
cout << "Min: " << min << endl;
cout << "Max: " << max << endl;
cout << "Range: " << range << endl;
return 0;
}
Step by step
Solved in 4 steps with 2 images









