Possible Duplicate:
Sum of float is not exact
So i have the code:
#include <iostream>
using std::cout;
using std::endl;
int main () {
float x = 0.0001;
float y = 0;
for (int i=0; i < 10000; i++) {
y += x;
}
cout << y << endl;
return 0;
}
I'm expecting the output to be 1, but I'm getting 1.00005, how come? What would i need to change to get "1" keeping the code more or less the same?