To calculate a leap year:
If the year is evenly divisible by 4, go to step 2. ...
If the year is evenly divisible by 100, go to step 3. ...
If the year is evenly divisible by 400, go to step 4. ...
The year is a leap year (it has 366 days).
The year is not a leap year (it has 365 days).
This could be represented by a Boolean value:
You can go to the different steps by using a series of nested if statements:
1 2 3 4 5 6 7 8 9 10 11 12
|
//Pseudo-code
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
bLeapYear = true;
}
}
}
else {
bLeapYear = false;
}
|
You only need one else because if the first statement is false, the others are also false.
Now you could also represent the month from if-else if blocks. From the main() function, you can print each one out and if the year is a leap year, then you can print that out.