Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that performs multiple die rolls using a random number generator

ID: 3794121 • Letter: W

Question

Write a program that performs multiple die rolls using a random number generator. Each die must be assigned an integer value between 1 and 6 inclusive, with uniform probability for each value. For each simulated roll, find the total of the three highest valued dice. Keep a count of the number of times each outcome occurs. Plot a histogram of the totals when the number of iteration is 10,000 Plot a histogram of the totals when the number of iteration is 1,000 Plot a histogram of the totals when the number of iteration is 300 Include your code in 12 point Courier New font.

Explanation / Answer

Hi sample the program will be like

int main()
{

const int array = 13;

int count[13], sum=0;
// init count
for(int j=0; j<13; j++)
count[j] = 0;

int dice1;
int dice2;

for ( int roll = 0; roll <=10000; roll++ ) {
dice1 = 1 + random() % 6;
dice2 = 1 + random() % 6;
count[dice1+dice2]++;
}

cout<<"sum of facevals"<<setw(13)<<"Frequency"<<endl;

for(int faceval=2; faceval<array;faceval++)
{
cout<<setw(7)<<faceval<<setw(13)<<count[faceval]<<endl;
sum += count[faceval];
}

cout << "sum: " << sum;


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote