Help with some array stuff
Basically, 36000 rolls of the dice. I want to output the sum of the two dice (done) the frequency of each sum (done) and the expected along with actual. Both of the later should be in percentage. I know how they would be calculated. Actual is freq/36000 and expected is just stats stuff (1k, 2k, 3k, 4k, 5k, 6k, 5k, 4k, 3k, 2k, 1k).
When I try to do freq/36000 I just can't get it to work.
Any suggestions for getting both of these other needed values into arrays and printed?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 13
int rollDice(void);
int main ()
{
int roll, sum, freq[SIZE] = {0};
float expected[SIZE] = {0}, actual[SIZE] = {0};
srand(time(NULL));
for (roll= 1; roll <= 36000; roll++)
{
sum = rollDice();
++freq[sum];
}
printf("%s%10s%12s%12s\n", "Sum", "Total", "Expected", "Actual");
for (sum =2; sum <= SIZE -1; sum++)
{
printf("%2d%10d%12f%12f\n", sum, freq[sum], expected[sum], actual[sum]);
}
return 0;
}
int rollDice(void)
{
int die1;
int die2;
int worksum;
die1 = 1 + ( rand() % 6 );
die2 = 1 + ( rand() % 6 );
worksum = die1 + die2;
return worksum;
}