The activity asks me to report a number of wagons and then asks me to assign a weight to each of them. I calculate the average of these weights and then subtract the average of the weights of each one of them to reach a common weight.
Here is where the number of wagons and their respective weights are reported:
int boxCarsQuantity;
int readValue
int numberPosition = 0;
int arrayWeight[0];
int sum=0;
int average=0;
printf("Insira a quantidade de vagões\n");
scanf("%d",&boxCarsQuantity);
for(int i = 0; i<boxCarsQuantity; i++)
{
printf("Insert the weight of a Boxcar\n");
scanf("%d",&readValue);
arrayWeight[numberPosition] = readValue;
sum=sum+arrayWeight[numberPosition];
numberPosition++;
}
Here I calculate the average weight of the wagons:
average=sum/boxCarsQuantity;
And here is where I display the average, and this is where I should display how much I should subtract from each wagon so that it reaches a common weight between the wagons:
printf("A média é: %d\n",average);
for(int e=0; e<boxCarsQuantity; e++)
{
printf("%d\n",arrayWeight[numberPosition2]-average);
numberPosition2++;
}
However, the last part is not running correctly, as I'm not sure how to subtract the positions of an array. How can I do this?