Possible Duplicate:
How should I do floating point comparison?
this is a snippet of code and I can't figure out what's wrong with it.
The if statement is evaluating the numbers incorrectly and going to "else".
double m,k;
m = (y3-y1)/(x3-x1);
k = m*(-x1)+y1;
cout <<"\n\n"<< m <<" "<< k << "\n";
cout <<"\n\n"<< ((-a)/b) <<" "<< c/b << "\n";
if(m==((-a)/b) && k==c/b)
{
cout << "\nTaisne sakrīt ar kādu no trīsstūra malām!" << endl;
goto beigas;
}
else
cout << "\n\n WRONG \n\n";
The user inputs values x1,y1,x3,y3,a,b,c - all are double.
It seems to work fine only with "m". And it is strange that when I tried the following, the if statement was true with the same values:
if(m==((-a)/b) && k<c/b)
Here is a screenshot to get the whole problem:
The code starts after user has input all the values.
Thanks, any help would be greatly appreciated!