Here's the question:
This program is intended to calculate the probability that if a person
rolls two fair sixed-sided dice, that they will get a total of 8. This
is done by looping through all the possibilities and counting those that
do not have a sum that exceeds 9. However, there are some bugs in this
file. Can you find them?
Code:
#include <stdio.h>
int main() {
int count, total;
for (i=1; i<6; i++)
for (j=0; j<=6; j++)
sum = i+j;
if (sum = 8)
count++;
total++;
printf("The probability of rolling an 8 is %lf.\n", count/total);
return 0;
}
So obviosuly, there are some undeclared variables so this is what I wrote:
Code:
int main() {
int count, total;
int i;
int j;
double sum=0;
for (i=1; i<6; i++) {
for (j=0; j<=6; j++)
sum = i+j;
if (sum = 8)
count++;
total++;
}
printf("The probability of rolling an 8 is %lf.\n", count/total);
system("PAUSE");
return 0;
}
From there, I'm not too clear of how to make it work