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

Redo this program, which tosses two dice and records the total output of each re

ID: 3559979 • Letter: R

Question

Redo this program, which tosses two dice and records the total output of each result, so that the results are in an array. (dice[di1+di2]=dice[di1+di2] +1;//where dice is an array of integers ... int dice[20];)

#include "stdafx.h"

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main()
{
   srand(time(NULL));

   int a[11] = {0};

   for(int i=0; i<10000; i++)
       {
       int dice_one = 1 + rand()%6;
       int dice_two = 1 + rand()%6;
       a[dice_one+dice_two-2]++;
       }
   for(int k=2; k<=12; k++)
       {
   cout << " The number of " << (k) << "'s was rolled " << a[k-2] << " times" << endl;
       }

return 0;
}

Explanation / Answer

#include "stdafx.h"

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main()
{
srand(time(NULL));

int dice[20] = {0};

for(int i=0; i<10000; i++)
{
int di1 = 1 + rand()%6;
int di2 = 1 + rand()%6;
dice[di1+di2]= dice[di1+di2] +1;
}

return 0;
}

/*OutPut*/

Output:

  1  2  3  4  5  6  7  8  9  10  11  
   The number of 2's was rolled 264 times   The number of 3's was rolled 527 times   The number of 4's was rolled 798 times   The number of 5's was rolled 1120 times   The number of 6's was rolled 1391 times   The number of 7's was rolled 1650 times   The number of 8's was rolled 1411 times   The number of 9's was rolled 1133 times   The number of 10's was rolled 858 times   The number of 11's was rolled 568 times   The number of 12's was rolled 280 times  
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