Question: Can somebody find the error in my code? In C I have to create a computer program that calculates the number of times the sum
Can somebody find the error in my code? In C I have to create a computer program that calculates the number of times the sum of randomly rolled dice equals each possible value from 2 to 12. I need it to display in both a numerical chart and a histogram chart. The hisogram chart is displaying but the numerical chart is not.
If you plug my code you will see I have both a histogram chart and a numerical chart that measures that counts the dice roles. Currently my histogram chart works fine but the numerical counter only counts the final dice roll that occurs. Could you fix the issue in my program? Thank you. This is what the final product is supposed to look like.
https://www.youtube.com/watch?v=M6i5gihrhOU

int main(void){
int i; // Loop counter iterates numRolls times
int numRolls; // User defined number of rolls
int die1; // Dice values
int die2; // Dice values
int rollTotal = 0; // Sum of dice values
int numTwos = 0;
int numThrees = 0;
int numFours = 0;
int numFives = 0;
int numSixes = 0; // Tracks number of 6s found
int numSevens = 0; // Tracks number of 7s found
int numEights = 0;
int numNines = 0;
int numTens = 0;
int numElevens = 0;
int numTwelves = 0;
printf("Enter number of rolls: ");
scanf("%d", &numRolls);
int a[13];
for(int i=0;i
a[i]=0;
srand(time(0));
while (numRolls >= 1) {
// Roll dice numRoll times
for (i = 0; i
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
rollTotal = die1 + die2;
a[rollTotal]++;
printf(" Roll %d is %d (%d+%d)", i + 1, rollTotal, die1, die2);
}
if(rollTotal == 2){
numTwos = numTwos + 1;
}
else if (rollTotal == 3){
numThrees = numThrees + 1;
}
else if (rollTotal == 4){
numFours = numFours + 1;
}
else if (rollTotal == 5){
numFives = numFives +1;
}
else if (rollTotal == 6){
numSixes = numSixes + 1;
}
else if (rollTotal == 7){
numSevens = numSevens + 1;
}
else if (rollTotal == 8){
numEights = numEights + 1;
}
else if (rollTotal == 9){
numNines = numNines + 1;
}
else if (rollTotal == 10){
numTens = numTens + 1;
}
else if (rollTotal == 11){
numElevens = numElevens + 1;
}
else if (rollTotal == 12){
numTwelves = numTwelves + 1;
}
printf(" Dice Roll Statistics: ");
printf("2: %d ",numTwos);
printf("3: %d ",numThrees);
printf("4: %d ",numFours);
printf("5: %d ",numFives);
printf("6: %d ",numSixes);
printf("7: %d ",numSevens);
printf("8: %d ",numEights);
printf("9: %d ",numNines);
printf("10: %d ",numTens);
printf("11: %d ",numElevens);
printf("12: %d ",numTwelves);
printf(" ");// Print statistics on dice rolls
int j;
for(i=2;i
{
printf("%d:\t",i);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
