writing array in loop form getting extra values

Why do I get extra values when writing the code in a loop? I am not sure why I am getting 0.001 , 0.002, etc Also why is my setprecision not getting most of the values to 2 decimal places?
Last edited on
Can't tell without seeing code.
It is obvious because you are doing it incorrectly.:)
Try to avoid doing this: (Line 2)

for(int i = 1; i <=5; i++)

If you want to do something 5 times - it looks like this :

for(int i = 0; i < 5; i++)

This is important so you don't over run array bounds.

Also, rather than hard code magic numbers, use a const variable :


const int SIZE = 5;

for(int i = 0; i < SIZE; i++)

That way if it needs to change, you can do it once, rather than changing it everywhere.

Last edited on
Topic archived. No new replies allowed.