I have this program that I need to write, but I'm so lost. I have gotten some things down and think I'm on the right track, but am stuck with how to set up the array and then how to do the tabular format...everything else I have down (if that's much at all..lol). Can someone help ASAP? thanks!!

Write a program that simulates the rolling of two dice. The program should use rand to roll the first dice and should use rand
again to roll the second dice. The sum of the two values should then be calculated. [note: each dice can show an integer value from 1-6, so the sum of the two values will vary from 2-12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums] Your program should roll the dice 36,000 times. use a single array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable (i.e. there are six ways to roll a 7, so approximately one sixth of the rolls should be 7).

11 Years
Discussion Span
Last Post by spaceytrin

Just store the sum totals in an 11-element array of ints. (there are 11 possible combinations for the sum of two 6-sided dice)

int num[11];

for (int i=0; i<36000; i++) {
    //  ...Calculate the two die rolls randomly..
    num[die1 + die2 - 2]++;

That should get you started...



ok, that makes sense, but I'm still unsure how to do an array...like I have to call back to my stored info from the array to make the final table and I don't know how to do that...sorry

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.