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
|
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void getDate(int& mon, int& day, int& year);
int ckDate(int mon, int day, int year);
void displayMsg(int message);
int main()
{
int mon, day, year, message;
string date;
while(cin)
{
getDate(mon,day,year); // call function getDate
int message=ckDate(mon,day,year); // cal function ckDate
cout << mon << "/" << day << "/" << year << "-";
displayMsg(message); //call function displayMsg
}
_getch();
return 0;
}
void getDate(int& mon, int& day, int& year)
{ cout << "\n\nEnter a date (mm/dd/yyyy): ";
cin >> mon;
cin.ignore(100, '/');
cin >> day;
cin.ignore(100, '/');
cin >> year;
}
int ckDate(int mon, int day, int year)
{
bool isLeapYear = false;
int resultNum = 0;
if ((year <= 999) || (year > 10000))
resultNum = 1;//attempting to change from multiple return statements with an integer to a variable resultNum.
if ((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 100 == 0 && year % 400 == 0))
isLeapYear = true;
switch (mon)
{
case 1:
if (day < 1 || day > 31)
resultNum = 3;
//resultNum = 3; attempting to assign variable to 3
//return resultNum;//returning it to displayMsg
break;
case 2:
if (isLeapYear && (day < 1 || day > 29))
resultNum = 5;
if (!isLeapYear && (day < 1 || day > 28))
resultNum = 6;
break;
case 3: // the month was not 1-12 so return 2
if (mon < 1 || mon > 12)
resultNum = 2;
break;
return resultNum;//appears to work correctly
}
return resultNum;//appears to work correctly
return 0;
}
void displayMsg(int message)
{
switch(message)
{
case 0:
cout << " Good Date";
break;
case 1:
cout << " Bad Year";
break;
case 2:
cout << " Bad Month";
break;
case 3:
cout << " Bad Day not 1-31";
break;
case 4:
cout << " Bad Day not 1-30";
break;
case 5:
cout << " Bad Day not 1-29";
break;
case 6:
cout << " Bad Day not 1-28";
break;
}
}
|