I'm trying to calculate the average and a minimum value from an array after I create random numbers. I tried a lot of different methods and nothing works. I don't know what I'm doing wrong so I kindly ask you to redirect me on the right path.
52:23: warning: 'weight' is used uninitialized in this function [-Wuninitialized]
69:25: warning: array subscript is above array bounds [-Warray-bounds]
77:17: warning: array subscript is above array bounds [-Warray-bounds]
int weight[n]; does not have element weight[n]. The last element of that array is weight[n-1].
Therefore, lines 52, 69, and 77 have an out of range error that causes undefined behaviour. Absolutely not good.
Line 66 changes the contents of the array.
The sum is initialized to 0 before the main loop. If you calculate average more than once, then you keep adding to previous sum. Same with minimum.