-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_year.cpp
More file actions
72 lines (69 loc) · 1.54 KB
/
Check_year.cpp
File metadata and controls
72 lines (69 loc) · 1.54 KB
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
#include <iostream>
using namespace std;
bool checkLeapYear(int year)
{
return ((year % 4 && year % 100 != 0) || year % 400 == 0) ? true : false;
}
int main()
{
while (true)
{
startAgain:
cout << "Input month?" << endl;
int month;
cin >> month;
if (month < 1 || month > 12)
{
cout << "Invalid" << endl;
}
else
{
switch (month)
{
case 4:
case 6:
case 9:
case 11:
cout << "Has 30 days!" << endl;
break;
case 2:
{
cout << "Input year?";
int year;
cin >> year;
if (year < 1900 || year > 9999)
{
cout << "Invalid" << endl;
}
else
{
if (checkLeapYear(year))
{
cout << "Has 29 days" << endl;
}
else
{
cout << "Has 28 days" << endl;
}
}
}
default:
cout << "Has 31 days" << endl;
break;
}
}
string option;
cout << "Do you want to continue?(Y/N): ";
cin >> option;
if (option == "Y")
{
goto startAgain;
}
else
{
break;
}
}
system("pause");
return 0;
}