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
|
bool isValidDate(int month, int day, int year)
{
int days_in_month[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
if (year % 4 == 0) {
days_in_month[2] = 29;
}
if ((month < 1) || (month > 12)) {
return false;
}
if ((day < 1) || (day > days_in_month[month])) {
return false;
}
return true;
}
void printDayOfBirth(int dayDetermined) {
if (dayDetermined = 0) {
cout << "Saturday";
}
else if (dayDetermined = 1) {
cout << "Sunday";
}
else if (dayDetermined = 2) {
cout << "Monday";
}
else if (dayDetermined = 3) {
cout << "Tuesday";
}
else if (dayDetermined = 4) {
cout << "Wednesday";
}
else if (dayDetermined = 5) {
cout << "Thursday";
}
else if (dayDetermined = 6) {
cout << "Friday";
}
return;
}
void determineDayOfBirth() {
int month = 0;
int day = 0;
int year = 0;
char x = '/';
stringstream birthday;
birthday << month << x << day << x << year;
cout << "Enter your date of birth" << endl;
cout << "format: month / day / year --> ";
cin >> birthday.str();
isValidDate(month, day, year);
if (isValidDate == false) {
cout << "Invalid date" << endl;
}
else {
determineDay(month, day, year);
cout << "You were born on a: " << printDayOfBirth << endl;
cout << "Have a great birthday!!!" << endl;
}
return;
}
| |