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(const bool is_leap_year, const int month);
- void print_calender(int 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;
- }
- int month = 0;
- while (!month)
- {
- cout << "Enter the month: ";
- cin >> month;
- if (month < 0 || month > 11)
- {
- cout << "That's not a valid month!" << endl;
- month = 0;
- }
- }
- cout << "There are " << days_in_month(leap_year, month) << " days in that month!" << 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;
- }
- int days_in_month(const bool is_leap_year, const int month)
- {
- int days_count = 0;
- switch (month)
- {
- case 8: case 3: case 5: case 10:
- days_count = 30;
- break;
- case 1:
- if (is_leap_year)
- {
- days_count = 29;
- }
- else
- {
- days_count = 28;
- }
- break;
- default:
- days_count = 31;
- }
- return days_count;
- }
- void print_calender(int month)
- {
- for (int month = 0; month < 12; ++month)
- {
- switch (month)
- {
- case 0:
- return "January";
- case 1:
- return "February";
- case 2:
- return "March";
- case 3:
- return "April";
- case 4:
- return "May";
- case 5:
- return "June";
- case 6:
- return "July";
- case 7:
- return "August";
- case 8:
- return "September";
- case 9:
- return "October";
- case 10:
- return "November";
- case 11:
- return "December";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement