Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool is_leap_year(const int year);
- int days_in_month
- int main()
- {
- int year = 0;
- int day = 0;
- bool day_valid = false;
- while (!year)
- {
- cout << "Enter the year: ";
- cin >> year;
- if (year < 0 || year > 9999)
- {
- cout << "That's not a valid year!" << endl;
- year = 0;
- }
- }
- while (!day_valid)
- {
- cout << "Enter the day of the week of January 1st, using 0 through 6." << endl;
- cout << "(0 = Sun, 1 = Mon, 2 = Tue, 3 = Wed, 4 = Thu, 5 Fri, 6 = Sat)" << endl;
- cin >> day;
- if (day < 0 || day > 6)
- cout << "That's not a valid day! Must be between 0 and 6!" << endl;
- else
- day_valid = true;
- }
- bool leap_year = is_leap_year(year);
- if (leap_year)
- {
- cout << year << " is a leap year." << endl;
- cout << "There are 29 days in February." << endl;
- }
- else
- {
- cout << year << " is not a leap year." << endl;
- cout << "There are 28 days in February." << endl;
- }
- }
- bool is_leap_year(const int year)
- {
- if (year%4==0)
- {
- if (year % 100 == 0 && year % 400 != 0)
- return false;
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement