Hello there,
i am trying to rewrite this program taht should take 2 integers- say 17 and 5 which represent 17 May and print out 18 May which is the next day.
I could use any constuctive comments and/or help that will enable me to get my program up and running quickly.
One of my questions is do i need to write another enum and switch functions for the days eg; mon - sat or can i already somehow shorten and manipulate my code? I am trying for something short and sweet, folks.
Code:
#include<stdio.h>
enum month {jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}; /*This allows yoou to name a finite set and to declare identifiers*/
typedef enum month month;
month previous_month(month M) /*this is a function definition*/
{
switch (M) /* like an if-else statement, if this month is true goto the M=month you chose*/
{
case jan:
M=dec;break;
case feb:
M=jan;break;
case mar:
M=feb;break;
case apr:
M=mar;break;
case may:
M=apr;break;
case jun:
M=may;break;
case jul:
M=jun;break;
case aug:
M=jul;break;
case sep:
M=aug;break;
case oct:
M=sep;break;
case nov:
M=oct;break;
case dec:
M=nov;break;
}
return M;
}
void print_month (month M) /*this is a function definition*/
{
switch (M) /* like an if-else statement, if this month is true goto the M=month you chose*/
{
case jan:
printf("January");break;
case feb:
printf("February");break;
case mar:
printf("March");break;
case apr:
printf("April");break;
case may:
printf("May");break;
case jun:
printf("June");break;
case jul:
printf("July");break;
case aug:
printf("August");break;
case sep:
printf("September");break;
case oct:
printf("October");break;
case nov:
printf("November");break;
case dec:
printf("December");break;
}
}
int main()
{
month M, N, sat;
printf("Table of months and thier predecessors\n");
scanf("%d%d", &M, &N);
printf("\n %16s%16s\n", "Month", "Day");
for (M = jan; M <= sat; ((int)M + 1))
{
printf("");
print_month(M); /*fucntion call to print month*/
printf("");
print_month(previous_month(M)); /*fucntion call to print previous month*/
putchar('\n');
return;
}
}