csansoon

P2.09 P29448 Correct dates

Sep 21st, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int d, m, a;
  6.   while (cin >> d >> m >> a){
  7.     bool cor = true;
  8.  
  9.     if(m > 0 and  m <= 12 and m != 2) {
  10.       if((m%2 == 0 and m <= 7) or (m%2 != 0 and m >=8)){
  11.     if (d > 0 and d <= 30) cor = true;
  12.     else cor = false;
  13.       }
  14.       else{
  15.       if (d > 0 and d <= 31) cor = true;
  16.       else cor = false;
  17.       }
  18.     }
  19.        
  20.     else if(m == 2) {
  21.       if((a%4 == 0 and (a%100) != 0) or ((a%100)== 0 and (a/100)%4 == 0)){
  22.     if (d > 0 and d <= 29) cor = true;
  23.     else cor = false;
  24.     }
  25.       else {
  26.     if (d > 0 and d <= 28) cor = true;
  27.     else cor = false;
  28.     }
  29.    }
  30.  
  31.   else cor = false;
  32.  
  33.   if(cor == true) cout << "Correct Date" << endl;
  34.   else cout << "Incorrect Date" << endl;
  35.  
  36.    
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment