Morteza Kashi
A program specifying if a year is a Leap year or not:
This example is a good example of taking advantage of nested if statements.
Before starting explaining the problem , I would like to give the exact definition of the leap year.
A leap year is a year having one of the following specification:
1-A year that is divisible by 4,100 and 400
2-A year that is divisible by 4 but it is not divisible by 100
We should conclude that a year is not a leap year if it is divisible by 4 and 100 but it is not divisible by 400.
We should also conclude that a year is not a leap year if it is not divisible by 4.
This program prompts user to enter a year between 1600 and 2400 and if the entered year is not in this range
it gives a suitable message and asks for another year. If the user enters the in-range year, the programs gives
a message saying if the year is a leap year or not. Then the program asks for another year and it goes on and on
in this way. If the user wants to exit the program, he or she may enter the year 2400 upon being asked. Then the
user may enter an integer to exit the program.
Please note that the result of the program will be written out to a file named "output.txt on the C drive as it is
arranged in the program.
Please find my C++ code for this program by clicking on the following link:
Please click on the following link, should you want to see the execution of the program. Save the Leap.exe file on
your desktop or somewhere else on your computer. Then, double click on it to see the execution of the program.
Please contact me by clicking HERE and filling out the coming simple form, should you have any question about this program.