Dice Rolling simulator

I am working on a dice rolling simulator for school that wants program to simulate rolling of 2 dice, use rand roll fist die and second die, sum of both dice should be calculated now
each die show integer value from 1 to 6
Program should roll dice 36000 times using 1 dimensional array to tally the number of times each possible sum appears
print tabular format.

Here is what I have so far but my program has a problem with me loop any help would be awesome thank you.


#include <iostream>
#include <time.h>
using namespace std;
int main()
{
int dIe1=0;
int dIe2=0;


int sUm;
int resultsArray[12];



dIe1 = rand() % 6 + 1;
dIe2 = rand() % 6 + 1;
sUm = dIe1 + dIe2;
{
if(sUm == 2)
resultsArray[2]++;
if(sUm == 3)
resultsArray[3]++;
if(sUm == 4)
resultsArray[4]++;
if(sUm == 5)
resultsArray[5]++;
if(sUm == 6)
resultsArray[6]++;
if(sUm == 7)
resultsArray[7]++;
if(sUm == 8)
resultsArray[8]++;
if(sUm == 9)
resultsArray[9]++;
if(sUm == 10)
resultsArray[10]++;
if(sUm == 11)
resultsArray[11]++;
if(sUm == 12)
resultsArray[12]++;
}





for (int i=0; i<36000;i++)

for(int j=2;j<13;j++)
cout << "The number of rolls for " << j << " is " << resultsArray[j] << endl;














system("PAUSE ");
return 0;
}
I don't have much time to type this out right now, but in my opinion, you are going about this extremely wrong. I would try a different approach, any loop for 0 to 36,000 is not the correct method. When I get home in a couple of hours I'll try to write out some code to get you started. For now, I would mathematically think of how you could accomplish this is a more reasonable manor.
1.) Your array only goes from 0-11, not 1-12, so you are accessing an out of bounds element should you get a sum of 12.

2.) Your first for loop is looping something not related to rolling the dice...I think you meant to put that around the "dice rolling" code?

3.) Same problem as 1, you are accessing element 12 which doesn't exist.
Topic archived. No new replies allowed.