You appear to have been set an impossible task.
You would need to start with a float or double. If you use an int then by definition the value you have is an integer. Here is the issue the float and double types are only approximations to any number, you can never count on them to be exact (particularly after calculations). Since you can convert a double to an integer by casting that means that the equality
d - int(d) == 0
where d is a double (or float) variable
is never true. Even if you expect d to be an integer value it wont be it will be an approximation and d - int(d) will have a small positive or negative result.
The best you can do is test to see if your double is close to an integer value
-
const double tolerance = 0.00001;
-
if (((d - tolerance) < int(d)) && ((d + tolerance) > int(d))
-
{
-
// d is close to an integer
-
}
-
You can set the tolerance to get an answer to the accuracy you require and I also have an alarm bell going in my head that this algorithm may need to be more complex to deal with negative values of d.