Question: In a main function declare an array of 1000 ints. Fill up the array with random numbers that represent the rolls of a die. That

In a main function declare an array of 1000 ints.

Fill up the array with random numbers that represent the rolls of a die. That means values from 1 to 6.

Write a loop that will count how many times each of the values appears in the array of 1000 die rolls.

Use an array of 6 elements to keep track of the counts, as opposed to 6 individual variables.

Print out how many times each value appears in the array.

1 occurs XXX times

2 occurs XXX times

my code

#include

#include

#include

int main()

{

int array[1000];

int x;

int sum[6];

srand(time(NULL));

for(x=0; x<1000; x++){

array[x]= (int)(rand()%6+1);

sum[array[x]]=(sum[array[x]]++);

}

for(x=1; x<7; x++){

printf("%d occured %d times. ", x , sum[6]);

}

return 0;

}

output

The dice rolled a 1, 1384960 times. The dice rolled a 2, 1384960 times. The dice rolled a 3, 1384960 times. The dice rolled a 4, 1384960 times. The dice rolled a 5, 1384960 times. The dice rolled a 6, 1384960 times.

i need help fixing this error

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!