finding a leap year

closed account (EAXiz8AR)
So I'm trying to write a program that produces the calendar given the year and month (which are both inputted by the user).

Anyways, the book I'm using tells me to use

1
2
3
4
bool isLeapYear(int year)
{
    return (year % 400 == 0 || (year % 4 == 0 && year % 100 == 0));
}


as the function to find the leap year. The problem is that I don't exactly understand the code here. Why does it try to find a remainder of zero for a given year divided by 400, for example? Can you guys explain this to me?


Thanks for reading!
I think it should be
return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));

A year is a leap year if it is a multiple of four but not a multiple of 100 or if it is a multiple of 400.
closed account (EAXiz8AR)
thanks!
Topic archived. No new replies allowed.