I'm trying to get my program to add up all of the values greater than integer x in the array so I can find their average. The following keeps giving me ridiculously large numbers:
for (int index = 0; index < 10; index++)
{
if (num[index] > x)
{
amountlarger++; //amount of numbers > x
sum2 = sum2 + num[index];
}
}
When I ask it to divide sum2 by amountlarger the math works fine, the calculated average is just far larger than it should be.
Aucun commentaire:
Enregistrer un commentaire