
Sadtoi R.
asked 01/20/21Write a program that prompts the user to enter the year and month
( C++ )
Write a program that prompts the user to enter the year and month, 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 2009 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2010 has 31 days
1 Expert Answer

Patrick B. answered 01/20/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
int Go(int month, int year)
{
int iReturn=0;
switch (month)
{
case 1 : { cout << "January"; break; }
case 2 : { cout << "February"; break; }
case 3 : { cout << "March"; break; }
case 4 : { cout << "April"; break; }
case 5 : { cout << "May"; break; }
case 6 : { cout << "June"; break; }
case 7 : { cout << "July"; break; }
case 8 : { cout << "August"; break; }
case 9 : { cout << "September"; break; }
case 10 : { cout << "October"; break; }
case 11 : { cout << "November"; break; }
case 12 : { cout << "December"; break; }
}
cout << " " << year << " : " ;
switch (month)
{
case 9:
case 4:
case 6:
case 11:
{
cout << "30 days" << endl;
break;
}
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
cout << "31 days" << endl;
break;
}
case 2:
{
if ((year %4)==0)
{
if ((year % 400) ==0)
{
cout << "29 days" << endl;
}
else
{
if ((year %100)==0)
{
cout << "28 days " << endl;
}
else
{
cout << "29 days" << endl;
}
}
}
else
{
cout << "28 days " << endl;
}
}
default:
{
//should not happen
iReturn=-1;
}
}
return(iReturn);
}
int main()
{
int month=-1;
while ((month<1) || (month>12))
{
cout << "Please input the month :>";
cin >> month;
}
int year=-1;
while (year<0)
{
cout << "Please input the year :>";
cin >> year;
}
Go(month,year);
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code uploaded to RESOURCES section01/20/21