-
Notifications
You must be signed in to change notification settings - Fork 47
/
dateTimeMonthCal.cpp
102 lines (93 loc) Β· 2.21 KB
/
dateTimeMonthCal.cpp
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
#include <iostream>
using namespace std;
int main()
{
int date1, month1, year1, date2, month2, year2, ctr = 0, ptr = 0;
cout << "enter date1 : ";
cin >> date1;
cout << endl;
cout << "enter month1 : ";
cin >> month1;
cout<<endl;
cout << "enter year1 : ";
cin >> year1;
cout << endl;
cout << "enter date2 : ";
cin >> date2;
cout << endl;
cout << "enter month2 : ";
cin >> month2;
cout << endl;
cout << "enter year2 : ";
cin >> year2;
cout <<endl;
if (year1 == year2)
{
if (month1 == month2)
{
cout << "date is " << (date1 - date2) << endl;
}
else
{
int month = month2 - month1;
int date = date2 - date1;
cout << "month is " << month << endl;
cout << "date is: " << date << endl;
}
}
else
{
if (month1 == month2)
{
if (date1 == date2)
{
cout << "12 months" << endl;
cout << "year=1 " << endl;
}
else
{
cout<<"12 months and "<<(date2-date1)<<" days"<<endl;
}
}
else
{
if(date1==date2)
{
for (int i = month1; i <= 12; i++)
{
ctr++;
if (i == 12)
{
break;
}
}
for (int i = 1; i <= month2; i++)
{
ptr++;
}
int total = ctr + ptr;
cout<<"total months are: "<<total<<endl;
}
else
{
for (int i = month1; i <= 12; i++)
{
ctr++;
if (i == 12)
{
ptr = ctr;
ctr = 0;
}
}
for (int i = 1; i <= month2; i++)
{
ctr++;
}
int total = ctr + ptr;
cout<<"total months are: "<<total<<endl;
cout<<"date are: "<<(date2-date1);
}
}
}
return 0;
}