I have to roll two dice 36,000 times and use a one-dimensional array to tally the number of times each number appears(2-12, with 7 being the most frequent sum and 2 and 12 the least frequent sums). My output just comes out with the whole table being 0's. What am I doing wrong?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int diceRoll(int die1, int die2, int tally[]);
int main(void) {
int x;
int y;
int z[13] = {0};
int sums = diceRoll(x, y, z);
srand(time(NULL));
for (int i = 2; i <= 12; i++)
{
printf("%3d%12d\n", i,sums);
sums += sums;
}
printf( "\nTotal number of rolls is %d",sums );
return 0;
}
int diceRoll(int die1, int die2, int tally[]) {
for(int i = 1; i <= 36000; i++) {
die1 = 1 + rand() % 6;
die2 = 1 + rand() % 6;
tally[die1 + die2]++;
}
return 0;
}```
Aucun commentaire:
Enregistrer un commentaire