Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int month, date, year, u, v, w, m, y, day;
- string weekday;
- cout << "Enter numeric values for date, month, and year -> ";
- cin >> month >> date >> year;
- bool validDate, leap = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
- if (month < 1 || month > 12 || date < 1 || date > 31 || year < 1583 || month > 12 || month < 0)
- validDate = false;
- else if (date == 31 && (month == 4 || month == 6 || month == 9 || month == 11))
- validDate = false;
- else if (month == 2)
- {
- if (leap)
- {
- if (date > 29)
- validDate = false;
- else
- validDate = true;
- }
- else if (date > 28)
- validDate = false;
- else
- validDate = true;
- }
- else
- validDate = true;
- {
- if (month == 1)
- {
- if (leap == true)
- m = 6;
- else
- m = 0;
- }
- else if (month == 2)
- {
- if (leap == true)
- m = 2;
- else
- m = 3;
- }
- else if (month == 3 || 11)
- m = 3;
- else if (month == 4 || 7)
- m = 6;
- else if (month == 5)
- m = 1;
- else if (month == 6)
- m = 4;
- else if (month == 8)
- m = 2;
- else if (month == 9 || 12)
- m = 5;
- else
- m = 0;
- }
- u = year / 100;
- v = year % 100;
- w = v / 4;
- y = u + v + w + m + date;
- day = y % 7;
- {
- if (day == 0)
- weekday = "Sunday";
- else if (day == 1)
- weekday = "Monday";
- else if (day == 2)
- weekday = "Tuesday";
- else if (day == 3)
- weekday = "Wednesday";
- else if (day == 4)
- weekday = "Thursday";
- else if (day == 5)
- weekday = "Friday";
- else
- weekday = "Saturday";
- }
- if (validDate)
- {
- if (leap)
- cout << weekday << " " << setw(2) << setfill('0') << month << "/" << setw(2) << setfill('0') << date << "/" << year
- << " is a valid date and is on a leap year." << endl;
- else
- cout << weekday << " " << setw(2) << setfill('0') << month << "/" << setw(2) << setfill('0') << date << "/" << year
- << " is a valid date and is not on a leap year." << endl;
- }
- else
- cout << month << "/" << date << "/" << year << " is not a valid date." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement