-
Notifications
You must be signed in to change notification settings - Fork 2
/
enum_find_next_month_date_1.c
100 lines (85 loc) · 2.64 KB
/
enum_find_next_month_date_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// author: jaydattpatel
#include <stdio.h>
enum month{jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec};
int get_month_days(enum month *m)
{
int max_days;
switch(*m)
{
case 0: max_days = 31; break;
case 1: max_days = 28; break;
case 2: max_days = 31; break;
case 3: max_days = 30; break;
case 4: max_days = 31; break;
case 5: max_days = 30; break;
case 6: max_days = 31; break;
case 7: max_days = 31; break;
case 8: max_days = 30; break;
case 9: max_days = 31; break;
case 10: max_days = 30; break;
case 11: max_days = 31; break;
default: printf("%d is an error\n", m);
}
return(max_days);
};
void print_month_date(enum month d,int date)
{
switch(d)
{
case jan: printf(" january %d\n",date); break;
case feb: printf(" february %d\n",date); break;
case mar: printf(" march %d\n",date); break;
case apr: printf(" april %d\n",date); break;
case may: printf(" may %d\n",date); break;
case jun: printf(" june %d\n",date); break;
case jul: printf(" july %d\n",date); break;
case aug: printf(" august %d\n",date); break;
case sep: printf(" september %d\n",date); break;
case oct: printf(" octomber %d\n",date); break;
case nov: printf(" november %d\n",date); break;
case dec: printf(" december %d\n",date); break;
default: printf("%d is an error\n", d);
}
}
void print_next_date(enum month *month,int *date)
{
enum month next_month,old_month = *month;
int next_date;
if((*date+1) > (get_month_days(&old_month))) //compare days of old month with (current date+1) for next month.
{
next_month = (*month+1) % 12; // increment in month with limit of total 12 months and move for next month
}
else
{
next_month = *month; //not incremented moved for no month change.
}
next_date = (*date+1) % (get_month_days(&old_month)); //increament date with limit of days of exist month
printf("Next date:");
print_month_date(next_month,next_date);
}
void print(enum month month,int date)
{
print_month_date(month,date);
print_next_date(&month,&date);
}
int main()
{
enum month month;
int date;
date = 31;
month = jan;
print(month,date);
date = 28;
month = feb;
print(month,date);
date = 14;
month = mar;
print(month,date);
date = 31;
month = oct;
print(month,date);
date = 31;
month = dec;
print(month,date);
return 0;
}