I'm supposed to be using enumeration to print a list of the months, and next to each month, the month that comes before it. Problem is the teacher didn't cover it too much, and the book we use, which is usually pretty good at explaining topics, only has one example and I don't even understand the concept. Can anyone help me out?
Code:
// Homework 4 Problem 1
#include <stdio.h>
enum month {jan=1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec};
typedef enum month month;
month previous_month(month m);
int main(void)
{
int i;
printf("MONTHS and PREVIOUS MONTHS\n");
for (i=1;i<12;++i)
printf("%d ",month);
month previous_month(month m);
printf("%d",prev_month);
return 0;
}
month previous_month(month m)
{
month prev_month;
switch (m)
{
case jan:
prev_month=dec;
break;
case feb:
prev_month=jan;
break;
case mar:
prev_month=feb;
break;
case apr:
prev_month=mar;
break;
case may:
prev_month=apr;
break;
case jun:
prev_month=may;
break;
case jul:
prev_month=jun;
break;
case aug:
prev_month=jul;
break;
case sep:
prev_month=aug;
break;
case oct:
prev_month=sep;
break;
case nov:
prev_month=oct;
break;
case dec:
prev_month=nov;
break;
return prev_month;
}
}