Write a program that simulates the rolling of two dice.The program should use ra
ID: 3643700 • Letter: W
Question
Write a program that simulates the rolling of two dice.The program should use rand to roll the first die andshould use rand again to roll the second die. Thesum of the two values should then be calculated.[note: since eachdie can show an integer value from 1 to 6, then the sum of the twovalues vary from 2 to 12, with 7 being the most frequent sum and 2and 12 the least frequent sums.] show the 36 possible combinationsof the two dice. your program should roll the two dice 36,000times. Use a single-subscripted array to tall the numbers of timeseach possible sum appears. PRint the results in tabular from. onesixth of all rolls should be 7.should look like this
1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
6 7 8 9 10 11 12
Explanation / Answer
#include #include #include using namespace std; int roll_dice(); int main(int argc, char *argv[]) { srand(time(NULL)); int roll1; int roll2; int sum; // default initialize all to 0 int frequencies[11] = {0}; for(int i = 0; i < 36000; ++i) { roll1 = roll_dice(); roll2 = roll_dice(); sum = roll1 + roll2; ++frequencies[sum-2]; } // Printing coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.