monthValid
to true
if the month entered is between 1 and 12, inclusive.
yearValid
to true
if the year is between 1000 and 1999, inclusive.
leapYear
to true
if the year is a leap year. Here is the leap year rule (there's more to it
than you may have thought!):
If the year is divisible by 4, it's a leap year UNLESS it's divisible by 100, in which case it's not a leap year UNLESS it's divisible by 400, in which case it is a leap year. If the year is not divisible by 4, it's not a leap year.Put another way, it's a leap year if a) it's divisible by 400, or b) it's divisible by 4 and it's not divisible by 100. So 1600 and 1512 are leap years, but 1700 and 1514 are not. You can use either compound boolean conditions, or nested if statements to set the value of
leapYear
.
daysInMonth
. If the month entered
is not valid, daysInMonth
should get 0. Note that to figure out
the number of days in February you'll need to check if it's a leap year (good thing you just wrote the code to store that information in leapYear
, right?!)