Guest User

Untitled

a guest
Oct 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. enum { jan=1, feb, mar, apr, may, jun, jul, aug, sep, octb, nov, decm };
  8.  
  9. int main() {
  10.     char date[8];
  11.     int month, day, max;
  12.  
  13.     cout<<"Enter date:"<<endl;
  14.     cin>>date;
  15.  
  16.     month = atoi(strtok(date, "."));
  17.     day = atoi(strtok(NULL, "."));
  18.  
  19.     switch(month) {
  20.     case feb:
  21.         max = 29;
  22.         break;
  23.     case apr: case jun: case sep: case nov:
  24.         max = 30;
  25.         break;
  26.     case jan: case mar: case may: case jul: case aug: case octb: case decm:
  27.         max = 31;
  28.         break;
  29.     default:
  30.         cout<<"Wrong date\n";
  31.         exit(0);
  32.     }
  33.  
  34.     if(day < 1 || max < day)
  35.         cout<<"Wrong date\n";
  36.     else
  37.         cout<<"OK\n";
  38.  
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment