I'm having a prob, with a program that's supposed to print values of y=2x+5, for x from -10 to 10.
I know it's really simple code, but it gets me a decimal value of i...when it should just subtract 0.2, so it ends up like -4.60001, or 7.79999...http://prntscr.com/2rxep2
Do not use float as iterating variable. 0.2 is about 1/5, so stepping from -50 to 50 would give you how many steps? More or less than your loop?
Wait, "0.2 is about 1/5"? Isn't it exactly so? No. Floating point numbers are not continuous; they are discrete, with limited precision. You do see that imprecision in your results. I guess that demostrating this feature is a purpose of your homework(?).
You can use tools from <iomanip> to format the output.
Floating-point numbers are inexact.
Not every real number can be represented perfectly as a float or double, so we have to stick with rough approximations, which is what you're seeing.
For instance, at least on my machine, setting float f = 0.02; will actually make f closer to 0.2000000029802322387695312500.
In your case, you can either reduce the precision of cout: cout.precision(3); // Display 3 digits
or you can switch to double (which has more precision, but it's still inexact) instead of float.
In either case, your i = 0 is still going to be messed up, because you start at i = -10 and then you keep adding approximations of 0.2, so you'll actually end up "missing" 0 by a very small margin (I end up with -5.03957e-006).