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

(Dice Rolling) Write a program that simulates the rolling of two dice. The progr

ID: 3839430 • Letter: #

Question

(Dice Rolling) Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. Your program should toll the two dice 36,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Make sure your program complies with assignment requirements in the syllabus. Be sure your program is READABLE. Save your program as a .cpp file and submit it as an attachment.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
int main(){
   int noTimes[10];
   for(int i=0;i<11;i++)
       noTimes[i]=0;
      
   int a,b,sum;
   for(long int i=0;i<36000;i++){
       a=rand()%6+1;
       b=rand()%6+1;
       sum=a+b-2;
       noTimes[sum]++;
   }  
   //long int s=0;
   for(int i=0;i<11;i++){
       cout<<i+2<<" "<<noTimes[i]<<endl;
// s=s+noTimes[i];
   }
   //cout<<s;
   return 0;
}