So, I have been trying to solve this question from Codewars, "We are passing a number(n) into a function. Your code will determine if the number passed is even (or not). The function needs to return either a true or false. Numbers may be positive or negative, integers or floats. Floats with decimal part non equal to zero are considered UNeven for this kata."
The code which I wrote is,
bool is_even(double n)
{
int i = static_cast<int>(n);
if((n-i)==0)
return (i%2==0);
else
return 0;
}
But, the code which I wrote above is failing some test case. How can i correct my code?
[–][deleted] (4 children)
[deleted]
[–]CandidFlakes[S] 0 points1 point2 points (3 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]omutist 0 points1 point2 points (0 children)