-
Notifications
You must be signed in to change notification settings - Fork 0
/
numberofDaysinMonth
32 lines (25 loc) · 1.7 KB
/
numberofDaysinMonth
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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "Enter year: " << endl; //asks user to input a year
int year;
cin >> year; //takes in the user's input of the year
cout << "Enter month: " << endl; //asks user to input a month
int month;
cin >> month; //takes in the user's input of the month
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
cout << "31 days" << endl; //creates an if statement that if these select months are inputted, then there are 31 days in that month
else if (month == 4 || month == 6 || month == 9 || month == 11)
cout << "30 days" << endl; //creates an else if statement that if these select months are inputted, then there are 30 days in that month
else if (month == 2 && year % 4 != 0)
cout << "28 days" << endl; //creates an else if statement that if February is inputted, and the year inputted is divisible by 4, then that year is not a leap year, and there are 28 days in that month
else if (month == 2 && year % 100 != 0)
cout << "29 days" << endl; //creates an else if statement that if February is inputted, and the year inputted is divisible by 100, then that year is a leap year, and there are 29 days in that month
else if (month == 2 && year % 400 != 0)
cout << "28 days" << endl; //creates an else if statement that if February is inputted, and the year inputted is divisible by 4 or 400, then that year is not a leap year, and there are 28 days in that month
else
cout << "29 days" << endl; //an else statement that if none other input is computed then the response is to output 29 days
return 0;
}