I recently started learning C++ from the starting and am currently studying from Bjarne Stroustrup's "Programming Principles and Practice using C++". There is an exercise to try to find the larger of two numbers inputted by the user and if they are less than 0.01 apart output "The numbers are almost equal". However the < operation I used in my if statement is working like <= for an unknown reason.
if(num1<num2)
{
diff=num2-num1;
std::cout<<"\nThe smaller value is: "<<num1;
std::cout<<"\nThe larger value is: "<<num2;
if(diff<0.01)
{
std::cout<<"\nThe numbers are almost equal";
}
}
If i input the numbers as 5 and 5.01 the inner if statement is triggered. But the weirder thing I noticed is that the if statement is not triggered if 64 and 64.01 are enetered. This is the case for all numbers from 64 to 127.99 after which the same error comes back.
I'm totally clueless as to what is causing this.
Aucun commentaire:
Enregistrer un commentaire