-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaysThisMonthsw.cpp
More file actions
49 lines (42 loc) · 993 Bytes
/
daysThisMonthsw.cpp
File metadata and controls
49 lines (42 loc) · 993 Bytes
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
//============daysThisMonthsw with switch statements for selection========
//Returns the number of days in a given month
//========================================================================
#include <cassert>
using namespace std;
int daysThisMonth(int month, int year)
{
assert(0 < month and month <=12);//is the month valid?
assert(0<year); //valid year?
int days=0;
switch(month)
{
case1: //January
case3: //March
case5: //May
case7: //July
case8: //August
case10: //October
case12: //December
days=31;
break;
case4: //April
case6: //June
case9: //September
case11: //November
days=30;
break;
case2:
if(year%4==0 and (year%100!=0 or year%400==0))
{
days= 29;// a leap year
}
else
{
days= 28;//not a leap year
}
break;
default:
assert(false);
}
return days;
}