hi all, I'm testing with floats for the first time and have discovered that you can't compare 2 floats due to rounding errors. I've read online that you must use an epsilon and test for less than, however I don't seem to be able to get it working with the below code. - when running the code below it it is looping through 6 floats testing for equality with f entered by the player, but even if I put something totally different from the options, the message "not a valid position" is never executed
void locks::try_lock()
{
print("\nEnter lock position: ");
float f; cin >> f;
int fexists = 1;
float epsilon = 0.0000001; // Not sure what the best value to put here is?
for (float &a : this->answers)
{
if ((a - f) < epsilon)
{
fexists = 0;
}
}
if (fexists == 1)
{
cout << endl << f << " is not a valid position\n\n";
Sleep(2000);
return;
}
}