I found two solutions to find out if two numbers have the same parity (both are odd numbers or both are even). In C++, they look like this:
if ((a+b)%2 == 0)
and
if (a%2 == b%2)
The problem is that the first one works on 100% of cases and the second one only on 80% of the cases (the tests of a problem that I have submitted on a website) and I do not understand why. For me, both lines of code should work fine on all cases. Can somebody explain me why does the first line of code work in all cases and the second one does not? And which method (those showed by me or another) would you recommend?