This program will tell you what the next day is. You give it the day and month and it will do all of the end of month and end of year calculations correctly. The only problem is that I want to use an enumeration to make the program length shorter. I have an enum, month, and typedef, but don't know how to insert it into the program correctly.
Code:#include <stdio.h> enum month {January=1, February=2, March=3, April=4, May=5, June=6, July=7, August=8, September=9, October=10, November=11, December=12}; typedef enum month month; int main(void) { int d = 0, m = 0; printf("\nEnter a day number (1~31): "); scanf("%d", &d); printf("\nEnter a month number (1~12): "); scanf("%d", &m); if ( ((m==1||m==3||m==5||m==7||m==8||m==10||m==12) && (d==31)) || ((m==4||m==6||m==9||m==11) && (d==30)) || ((m==2) && (d==28)) ) { if((m==1||m==3||m==5||m==7||m==8||m==10||m==12) && (d==31)) {d = 1; m += 1;} if((m==4||m==6||m==9||m==11) && (d==30)) {d = 1; m += 1;} if((m==2) && (d==28)) {d = 1; m += 1;} } else {d += 1;} if(m==13) {m = 1;} printf("\n%s%d", "The next day is: ", d); printf("\n%s", "The next month is: "); switch(m) { case 1: printf("January"); break; case 2: printf("February"); break; case 3: printf("March"); break; case 4: printf("April"); break; case 5: printf("May"); break; case 6: printf("June"); break; case 7: printf("July"); break; case 8: printf("August"); break; case 9: printf("September"); break; case 10: printf("October"); break; case 11: printf("November"); break; case 12: printf("December"); break; } printf("\n"); }
If anyone could help me add it in and achieve the same result, that would be cool.
P.S. > Sorry if the code is hard to read/follow! <