Advertisement
Guest User

work_in_class

a guest
Oct 28th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int days, months, year;
  8.     int maxDays;
  9.     cin >> days >> months >> year;
  10.  
  11.  
  12.     bool isLeap = (year % 400 == 0) || (year % 100 != 0 && year % 4 == 0);
  13.  
  14.  
  15.     if (!cin || months<1 || months>12)
  16.     {
  17.         cout << "Incorrect input!" << endl;
  18.         return 1;
  19.     }
  20.  
  21.  
  22. /*  if (months == 1 || months == 3 || months == 5
  23.         || months == 7 || months == 8 || months == 10 || months == 12)
  24.     {
  25.         maxDays = 31;
  26.     }
  27.     else if (months == 4 || months == 6 || months == 9 || months == 11)
  28.     {
  29.         maxDays = 30;
  30.     }
  31.     else maxDays = 28 + isLeap;
  32. */
  33.  
  34.     bool isCorrect = true;
  35.  
  36.  
  37.     switch (months)
  38.     {
  39.      case 1:
  40.      case 3:
  41.      case 5:
  42.      case 7:
  43.      case 8:
  44.      case 10:
  45.      case 12: maxDays = 31;  break;
  46.  
  47.      case 4:
  48.      case 6:
  49.      case 9:
  50.      case 11: maxDays = 30;  break;
  51.  
  52.      case 2: maxDays = 28 + isLeap; break;
  53.      default:isCorrect = false; break;
  54.     }
  55.    
  56.  
  57.     if (!isCorrect) {
  58.         cout << "Incorrect input!" << endl;
  59.         return 1;
  60.     }
  61.  
  62.     if (days<1 || days>maxDays)
  63.     {
  64.         cout << "Incorrect input!" << endl;
  65.         return 1;
  66.     }
  67.     cout << days << "." << months << "." << year << endl;
  68.    
  69.     system("pause");
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement