Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


0 votes
asked in CSC201 by (108 points)

1 Answer

0 votes

As we know, the arithmetic is really accomplished in base 2. This can lead to some slight differences in decimal digits. Add to that the "banker's rounding" and some strange differences occur.

I saw this same difference earlier today in another student's program. The student with this difference had initialized the totals to zero before the loop and added the initial populations after the loop before dividing to compute the average.

Instead, I initialized the totals to the initial populations before the loop.

That made a difference in the fourth decimal digit and rounding to 3 decimal places made the third decimal digit different.

Check to see how you initialized the accumulating total variables before the loop.

answered by (4.2k points)