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

Can somebody find the error in my code? In C I have

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);

for(j=0;j

printf("*");

printf(" ");

}

printf("Enter number of rolls: ");

scanf("%d", &numRolls);

}

return 0;

}

Create different versions of the program that: 1. Calculates the number of times the sum of the randomly rolled dice equals each possible value from 2 to 12. 2. Repeatedly asks the user for the number of times to roll the dice, quitting only when the user-entered number is less than 1. Hint:Use a while loop that will execute as long as numRolls is greater than 1. Be sure to initialize numRolls correctly. 3 Prints a histogram in which the total number of times the dice rolls equals each possible value is displayed by printing a character like *that number of times, as shown below Figure 6.13.1: Histogram showing total number of dice rolls for each possible value. Dice roll histogram: 2: 3 4: 5: 6* 7: 8: 9 10: Feedback

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!