#include using namespace std; /* * This interactive C++ program determines in a year is a leap year. * * creator: g.d.thurman * created: 2008.02.29 [leap day of 2008] */ int main(int, char**) { int y; do { cout << "Enter a year (0 to exit): "; cin >> y; if (cin.fail()) { cout << "*** error: you must enter an integer" << endl; return EXIT_FAILURE; } else if (!y) return EXIT_SUCCESS; if (y < 0) { cout << "negative integers are not allowed" << endl;; continue; } /* [source: TimeAndDate.com] * 1. Every year that is divisible by four is a leap year; * 2. of those years, if it can be divided by 100, it is NOT * a leap year, unless * 3. the year is divisible by 400. Then it is a leap year. * Note: Before 1752, all years divisible by 4 were leap years. */ cout << y << " is "; if (y % 4) cout << "not "; else if (y >= 1752 && !(y % 100) && (y % 400)) cout << "not "; cout << "a leap year" << endl; } while(y); }