This code is checking if the given day is in the calendar (that is its number is between current month's minimum and maximum number).
The following line
Quote:
if (month ==2 && testDay ==24 &&(year %400 ==0 || (year %4 ==0 && year %100!=0) ) )
Is wrong: it should be
if (month ==2 && testDay ==29 && (year %400 ==0 || (year %4 ==0 && year %100!=0) ) )
It checks if
29
th of february is a valid day, that is if current year is a
leap year.
You know, a year is leap if it is exactly divisible by
4
but it isn't a century year (e.g.
1900
), unless it is also divisible by
400
(e.g.
2000
).
By the way, the indentation is misleading.
[update]
As noted by
OriginalGriff (I have overlooked it)
Quote:
return 1 ; // maintain object n consistent state
is plain madness: if you detect an invalid input,
you have to signal it.
[/update]