probability of dice throw
I have wriiten the following code that generates a random dice throw 36000 times. It then prints out the number of times each pair is thrown. I want to also output the actual and expected probabilities fo each throw. Do I need another for loop to jump through the array, or what am i missing here. Any help would be greatly appreciated. Thanks to all the people who are smarter than the average bear.
code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 13 /*0-12*/
int main ()
{
int die_one, die_two, roll,j,sum, freq[SIZE] = {0};
float actual;
srand(time(NULL));
for (roll= 1; roll <= 36000; roll++)
{
die_one = rand () % 6 +1;
die_two = rand () % 6 +1;
sum = die_one + die_two;
++freq [sum];
}
printf("%s%10s%20s%22s\n", "Sum", "Freq", "Expected", "Actual");
for (sum =2; sum <= SIZE -1; sum++)
{
printf("%2d%10d%20f\n", sum, freq[sum], actual);
}
return 0;
}
Sum Freq Expected Actual
2 947
3 2034
4 2998
5 4063
6 5075
7 5889
8 4986
9 4005
10 2943
12 1020
Press any key to continue