1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <iostream>
#include <conio.h>
using namespace std;
void getDate( int&, int&, int&);
int ckDate( int, int, int);
void displayMsg( int);
int main(){
int month;
int day;
int year;
int check;
while(cin){
getDate(month, day, year);
check = ckDate(month, day, year);
displayMsg(check);
}
_getch();
return 0;
}
void getDate(int& m, int& d, int& y){
cout << "Enter a date (mm/dd/yyyy): ";
cin >> m >> d >> y;
}
int ckDate (int m, int d, int y){
int check = 0;
switch(check){
case 1:
if (y < 999 && y > 10000)
{
check = 1;
}
break;
case 2:
if (m < 1 || m > 12)
{
check = 2;
}
break;
case 3:
while (m == 1 || m == 3 || m == 5 || m == 7 || m == 8|| m == 10 || m == 12)
if (d < 1 || d > 31)
{
check = 3;
}
break;
case 4:
while (m == 4 ||m == 6 || m == 9 || m == 11)
if (d < 1 || d > 30)
{
check = 4;
}
break;
case 5:
while (m == 2){
if (y % 400 == 0)
{
if (y % 100 == 0 && y % 4 == 0)
{
if (d < 1 && d > 29)
{
check = 5;
}
}
}
else if (d < 1 && d > 28)
{
check = 6;
}
}
break;
default:
check = 0;
}
return check;
}
void displayMsg(int check){
if (check == 0)
{
cout << "Good Date\n";
}
else if (check == 1)
{
cout << "Bad Year\n";
}
else if (check == 2)
{
cout << "Bad Month\n";
}
else if (check == 3)
{
cout << "Bad Day not 1-31\n";
}
else if (check == 4)
{
cout << "Bad Day not 1-30\n";
}
else if (check == 5)
{
cout << "Bad Day not 1-29\n";
}
else if (check == 6)
{
cout << "Bad Day not 1-28\n" ;
}
}
|