Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int days, months, year;
- int maxDays;
- cin >> days >> months >> year;
- bool isLeap = (year % 400 == 0) || (year % 100 != 0 && year % 4 == 0);
- if (!cin || months<1 || months>12)
- {
- cout << "Incorrect input!" << endl;
- return 1;
- }
- /* if (months == 1 || months == 3 || months == 5
- || months == 7 || months == 8 || months == 10 || months == 12)
- {
- maxDays = 31;
- }
- else if (months == 4 || months == 6 || months == 9 || months == 11)
- {
- maxDays = 30;
- }
- else maxDays = 28 + isLeap;
- */
- bool isCorrect = true;
- switch (months)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12: maxDays = 31; break;
- case 4:
- case 6:
- case 9:
- case 11: maxDays = 30; break;
- case 2: maxDays = 28 + isLeap; break;
- default:isCorrect = false; break;
- }
- if (!isCorrect) {
- cout << "Incorrect input!" << endl;
- return 1;
- }
- if (days<1 || days>maxDays)
- {
- cout << "Incorrect input!" << endl;
- return 1;
- }
- cout << days << "." << months << "." << year << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement