I have to write a program the takes in two integers by the user, a and b, where a corresponds to the month of the year ( 1 = jan, 2 = feb etc.). The program has to print the month that comes after "a" and the following "b" months. This is what I have so far, but for every two integers I enter, I always get the same output: "January, February". Any help is appreciated.
#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 next_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=feb;break;
case feb:
M=mar;break;
case mar:
M=apr;break;
case apr:
M=may;break;
case may:
M=jun;break;
case jun:
M=jul;break;
case jul:
M=aug;break;
case aug:
M=sep;break;
case sep:
M=oct;break;
case oct:
M=nov;break;
case nov:
M=dec;break;
case dec:
M=jan;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(void)
{
month M, N, sat;
printf("Please enter two integers:\n");
scanf("%d%d", &M, &N);
for (M = jan; M <= N; ((int)M++))
{
printf(" ");
print_month(M); /*function call to print month*/
printf(" ");
print_month(next_month(M)); /*function call to print previous month*/
putchar('\n');
return;
}
}