-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
103 lines (78 loc) · 2.45 KB
/
Source.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
103
#include <iostream>
using namespace std;
struct Date {
int year;
int month;
int day;
Date(int y, int m, int d) : year(y), month(m), day(d) {}
Date() : year(0000), month(00), day(00) {}
};
int daysInMonth(int month, int year) {
/*
* 1 = JANUARY
* 2 = FEBRUARY [28/29 depending]
* 3 = MARCH
* 4 = APRIL [30 days]
* 5 = MAY
* 6 = JUNE [30 days]
* 7 = JULY
* 8 = AUGUST
* 9 = SEPTEMBER [30 days]
* 10 = OCTOBER
* 11 = NOVEMBER
* 12 = DECEMBER
*/
if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
else if (month == 2) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
return 29;
}
else {
return 28;
}
}
else {
return 31;
}
}
int daysToNextChristmas(const Date& currentDate) {
Date nextChristmas(currentDate.year, 12, 25);
int daysRemaining = 0;
// when christmas has passed
if (currentDate.month == 12 && currentDate.day > 25) {
// we get the days left in december
daysRemaining = 31 - currentDate.day;
for (int month = 1; month < 12; ++month) {
//the year section checks if the next years is a leap year, starting from the year other the current year
daysRemaining += daysInMonth(month,currentDate.year+1);
}
// add 25 days to get to get to christ as we are in december anyhow you get it bro
daysRemaining += nextChristmas.day;
}
else if (currentDate.month == 12 && currentDate.day < 25) {
return daysRemaining = nextChristmas.day - currentDate.day;
}
else {
daysRemaining += daysInMonth(currentDate.month, currentDate.year) - currentDate.day;
for (int month = currentDate.month + 1; month < 12; ++month) {
daysRemaining += daysInMonth(month,currentDate.year);
}
daysRemaining += nextChristmas.day;
}
return daysRemaining;
}
int main() {
Date currentDate;
cout << "Enter the current date (YYYY MM DD): ";
cin >> currentDate.year >> currentDate.month >> currentDate.day;
if (currentDate.month == 12 && currentDate.day == 25) {
cout << "Merry Christmas \n";
}
else {
int daysRemaining = daysToNextChristmas(currentDate);
cout << daysRemaining << "Days remaining until Christmas " << currentDate.year++ << endl;
}
return 0;
}