Originally Posted by
iceaway
I would suggest changing the contents of your while-loop a bit. First read the number, then check if it is below zero or not. If it is non-negative, add it to sum and increase the counter, if it is negative, exit the loop.
I would not use i as a float value here, since it it just a counter and it does not need floating point precision. Instead I would make your avg variable a float, and before printing the average, calculate the average into the avg variable and print that instead.
Code:
float avg;
...
avg = (float)sum/i;
He can also do it in the printf() as he is now...
Code:
printf("Average: %0.2f\n", ((float) sum) / i );