Probably not a good idea to use == with floating point values.
Floating points are not very likely to have the
exact same value as another floating point. Even if the user enters "3.0", that might not equal exactly 3.0 (and thus a == 3.0 check might fail unexpectedly). The reasons for this are because of the way floating points are handled. I don't really care to get into it in detail, but you should know about it.
Anyway... you're generally better off with sticking to range checks. Like >=, <=, >, < when dealing with floating points.
You can do this with a simple else if chain, not unlike your original post:
1 2 3 4 5 6 7 8
|
if(point >= 3.0)
cout << "point >= 3.0";
else if(point >= 2.0)
cout << "3.0 > point >= 2.0";
else if(point >= 1.0)
cout << "2.0 > point >= 1.0";
else
cout << "1.0 > point";
|
BettyBoop's suggestion of doing this:
else if (3.00 > point && point > 2.00)
will also work, but is redundant. The
else
already ensures that point <= 3.0, so there's no reason to check for it again.