-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.c
194 lines (177 loc) · 5.84 KB
/
Main.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include<stdio.h>
#include "Dtmanip.h"
main()
{ //declaration of variables
int choice;
char date[11],date1[11],date2[11];
char dayWeek[10],newDate[11];
int iyear,imonth,dyear,dmonth,days;
int y,m,d;
//asking of choice
while(1)
{ //providing choices
printf("1. Date validation\n");
printf("2. Compare Dates\n");
printf("3. Difference of Dates in days\n");
printf("4. Difference of Dates in years months days\n");
printf("5. Day of week\n");
printf("6. Add years\n");
printf("7. Add months\n");
printf("8. Add days\n");
printf("9. Subtract years\n");
printf("10. Subtract months\n");
printf("11. Subtract days\n");
printf("12. Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(isValid(date))
printf("Valid date\n");
if(!isValid(date))
printf("Not a Valid date\n");
break;
case 2:
printf("Enter first date (dd/mm/yyyy) : ");
scanf("%s",date1);
printf("Enter second date (dd/mm/yyyy) : ");
scanf("%s",date2);
if(!isValid(date1) || !isValid(date2))
{
printf("Enter only valid dates\n");
break;
}
if(cmpDate(date1,date2)==0)
printf("Dates are same\n");
else if(cmpDate(date1,date2)==1)
printf("Date1 is less than Date2\n");
else if(cmpDate(date1,date2)==-1)
printf("Date1 is greater than date2\n");
break;
case 3:
printf("Enter first date (dd/mm/yyyy) : ");
scanf("%s",date1);
printf("Enter second date (dd/mm/yyyy) : ");
scanf("%s",date2);
if(!isValid(date1) || !isValid(date2))
{
printf("Enter only valid dates\n");
break;
}
if(cmpDate(date1,date2)==1)
days=diffDays(date1,date2);
else
days =diffDays(date2,date1);
printf("Difference in days = %d\n",days);
break;
case 4:
printf("Enter first date (dd/mm/yyyy) : ");
scanf("%s",date1);
printf("Enter second date (dd/mm/yyyy) : ");
scanf("%s",date2);
if(!isValid(date1) || !isValid(date2))
{
printf("Enter only valid dates\n");
break;
}
if(cmpDate(date1,date2)==1)
diffYMD(date1,date2,&y,&m,&d);
else
diffYMD(date2,date1,&y,&m,&d);
printf("Difference of the two dates is : ");
printf("%d years %d months %d days \n",y,m,d);
break;
case 5:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
weekDay(date,dayWeek);
printf("Day of week is %s \n",dayWeek);
break;
case 6:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of years to be added : ");
scanf("%d",&iyear);
addYear(date,iyear,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 7:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of months to be added : ");
scanf("%d",&imonth);
addMonth(date,imonth,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 8:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of days to be added : ");
scanf("%d",&days);
addDays(date,days,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 9:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of years to be subtracted : ");
scanf("%d",&dyear);
subYear(date,dyear,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 10:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of months to be subtracted : ");
scanf("%d",&dmonth);
subMonth(date,dmonth,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 11:
printf("Enter date (dd/mm/yyyy) : ");
scanf("%s",date);
if(!isValid(date))
{
printf("Enter a valid date\n");
break;
}
printf("Enter the no of days to be subtracted : ");
scanf("%d",&days);
subDays(date,days,newDate);
printf("Now the new date is %s\n",newDate);
break;
case 12:
exit(1);
default:
printf("Wrong choice\n");
}
}
}