I am writing a class for holding dates in c++, and I found the following problem:
I have a number of days N
since a reference date (in
This
bool IsLeapYear(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) && (year % 400 == 0)) return true;
else return false;
}
is incorrect. It returns false
for 2000. Better:
bool IsLeapYear(int year)
{
if (year % 400 == 0) return true;
if ((year % 4 == 0) && (year % 100 != 0)) return true;
return false;
}