Write a program that prompts the user to enter the year and month in this order, and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days.
```
```
#include
using namespace std;
int main()
{
cout << "Enter a year: ";
int year;
cin >> year;
cout << "Enter a month in the year (e.g., 1 for Jan): ";
int month;
cin >> month;
int numberOfDaysInMonth = 0;
switch (month)
{
case 1:
cout << "January " << year;
numberOfDaysInMonth = 31;
break;
case 2:
cout << "Feburary " << year;
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
numberOfDaysInMonth = 29;
else
numberOfDaysInMonth = 28;
break;
case 3:
cout << "March " << year;
numberOfDaysInMonth = 31;
break;
case 4:
cout << "April " << year;
numberOfDaysInMonth = 30;
break;
case 5:
cout << "May " << year;
numberOfDaysInMonth = 31;
break;
case 6:
cout << "June " << year;
numberOfDaysInMonth = 30;
break;
case 7:
cout << "July " << year;
numberOfDaysInMonth = 31;
break;
case 8:
cout << "August " << year;
numberOfDaysInMonth = 31;
break;
case 9:
cout << "September " << year;
numberOfDaysInMonth = 30;
break;
case 10:
cout << "October " << year;
numberOfDaysInMonth = 31;
break;
case 11:
cout << "November " << year;
numberOfDaysInMonth = 30;
break;
case 12:
cout << "December " << year;
numberOfDaysInMonth = 31;
break;
}
cout << " has " << numberOfDaysInMonth << " days";
return 0;
}
```
You might also like to view...
Which of the following is used to uniquely identify a computer on a network?
A. Network ID B. Serial number C. IP address D. Microsoft ID
You must assign a unique title to each content control.
Answer the following statement true (T) or false (F)
Netstat shows what ____________________ are active and can also provide statistics based on ports or protocols (TCP, UDP, and so on).
Fill in the blank(s) with the appropriate word(s).
Which of the following is not a flag that can be used in the printf format-control string?
a) 0 b) + c) / d) #