Originally Posted by
The Brain
Code:
//if year is evenly divisible by 400 OR year is evenly divisible by 4 AND year is not evenly divisible by 100
if(year%400 == 0 || year%4 == 0 && !(year%100 == 0))
You might want to write this as
Code:
if (year%400 == 0 || (year%4 == 0 && year%100 != 0))
since not everyone knows off the top of their head that && has higher precedence than || (I had to look it up).
Edit: If efficiency matters, you can also rewrite it as
Code:
if ((year%4 == 0 && year%100 != 0) || year%400 == 0)
since the first condition is much more likely to be true, allowing the || shortcutting to skip the second condition. The two conditions for && should be left as is, since the first one is much more likely to be false, allowing the && shortcutting to skip the second one.