/*************************************************************************** * date.c * Unit 3.1 * Demonstrates use of enums and structs ***************************************************************************/ #include #include typedef enum Month { January = 1, February, March, April, May, June, July, August, September, October, November, December } Month; typedef struct Date { Month month; int day; int year; } Date; const int daysPerMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* function prototypes */ void printDate(Date date); bool isLeapYear(int year); int main() { Date today; Date tomorrow; printf("Enter today's date (mm dd yyyy without leading zeros): "); scanf ("%i%i%i", &today.month, &today.day, &today.year); bool leap = isLeapYear(today.year); if (leap && today.month == February) { if (today.day == 29) { tomorrow.day = 1; tomorrow.month = March; } else if (today.day == 28) { tomorrow.day = 29; tomorrow.month = today.month; } tomorrow.year = today.year; } /* set tomorrow based on what today is */ if (today.day != daysPerMonth[today.month-1]) { tomorrow.day = today.day + 1; tomorrow.month = today.month; tomorrow.year = today.year; } else if (today.month == December) { // end of year tomorrow.day = 1; tomorrow.month = January; tomorrow.year = today.year + 1; } else { // end of month tomorrow.day = 1; tomorrow.month = today.month + 1; tomorrow.year = today.year; } printf("Tomorrow is "); printDate(tomorrow); } bool isLeapYear(int year) { } /* print date */ void printDate(Date date) { switch(date.month) { case January: printf("January"); break; case February: printf("February"); break; case March: printf("March"); break; case April: printf("April"); break; case May: printf("May"); break; case June: printf("June"); case July: printf("July"); case August: printf("August"); break; case September: printf("September"); break; case October: printf("October"); break; case November: printf("November"); break; case December: printf("December"); break; default: printf("Invalid month"); } printf (" %d, %d\n ", date.day, date.year); }