Code:
#include<iostream>
using namespace std;
int main(void)
{
float num1 = 112.0f / 9.0f; // = 12.4444
float num2 = 12.4444444f;
cout << num1 << '\n'
<< num2 << '\n';
if(num1 == num2) // why doesnt num1 == num2
{
cout << "yeah\n";
}
return(0);
}
You forgot a few numbers. The first one was 12.4444444 and the other 12.4444000 in your code. However there's another important issue that causes (note: 'causes', not 'can cause') troubles, it didn't in this case but it usually does and the bigger the larger the equation the bigger the chances are.
As it has been pointed out floating-point numbers are approximations so when you compare them you should compare them within a range like Sly did instead of just using the == operator.