Advertisement
Nikolcho

Get tomorrow date

Dec 5th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int day, month, year;
  8.     cout << "Vuvedi denq: ";
  9.     cin >> day;
  10.     cout << "Vuvedi month: ";
  11.     cin >> month;
  12.     cout << "Vuvedi year: ";
  13.     cin >> year;
  14.    
  15.     if(month < 1 || month > 12)
  16.     {
  17.         cout << "Vuvedete pravilen mesec";
  18.         return 0;
  19.     }
  20.     if(day < 1 || day > 31)
  21.     {
  22.         cout << "Vuvedi pravilen den";
  23.         return 0;
  24.     }
  25.     else if(day > 29 && month == 2)
  26.     {
  27.         cout << "Vuvedi pravilen den";
  28.         return 0;
  29.     }
  30.     else if(day == 29 && year % 400 != 0)
  31.     {
  32.         cout << "Vuvedi pravilen den";
  33.         return 0;
  34.     }
  35.     if(day == 31 && (month == 4 || month == 6 || month == 9 || month == 11))
  36.     {
  37.         cout << "Vuvedi pravilen den";
  38.         return 0;
  39.     }
  40.    
  41.     int tomorrowYear = year;
  42.     int tomorrowMonth = month;
  43.     int tomorrowDay = day + 1; 
  44.    
  45.    
  46.     switch(tomorrowDay)
  47.     {
  48.         case 32:
  49.             switch(tomorrowMonth)
  50.             {
  51.                 case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  52.                     tomorrowDay = 1;
  53.                     tomorrowMonth++;
  54.                     if(tomorrowMonth == 13)
  55.                     {
  56.                         tomorrowMonth = 1;
  57.                         tomorrowYear++;
  58.                     }
  59.                     break;
  60.             }
  61.         break;
  62.         case 31:
  63.             switch(tomorrowMonth)
  64.             {
  65.                 case 4: case 6: case 9: case 11:
  66.                     tomorrowDay = 1;
  67.                     tomorrowMonth++;
  68.                     break;
  69.             }
  70.         break;
  71.         case 30:
  72.             if(tomorrowMonth == 2)
  73.             {
  74.             tomorrowDay = 1;
  75.                     tomorrowMonth = 3; 
  76.             }
  77.             break;
  78.         case 29:
  79.              if (tomorrowMonth == 2)
  80.               {
  81.                 if (tomorrowYear % 400 == 0)
  82.                 {
  83.                 }                      
  84.                 else
  85.                 {
  86.                     tomorrowDay = 1;
  87.                     tomorrowMonth = 3;
  88.                 }      
  89.             }
  90.          break;
  91.            
  92.     }
  93.     cout << "utre e: " << tomorrowDay << "/" << tomorrowMonth << "/" << tomorrowYear;
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement