Write a program that will display a calendar given a month and year as an input to the program. Will display only single month of year given. Here it’s that if given input as ( April 2003) will display only the given month of the year.
#include <iostream>
using namespace std;
int main()
{
int month, year, days;
char ch;
cout << "Enter a month and year: ";
cin >> month>> year;
while (true)
{
switch (month)
{
case 1: "January"; days = 31; break;
case 2: "February"; days = 31;
if (year % 4 != 0) days = 28;
else days = 29; break;
case 3: "March"; days = 31; break;
case 4: "April"; days = 30; break;
case 5: "May"; days = 31; break;
case 6: "June"; days = 30; break;
case 7: "July"; days = 31; break;
case 8: "August"; days = 31; break;
case 9: "September"; days = 30; break;
case 10: "October"; days = 31; break;
case 11: "November"; days = 30; break;
case 12: "December "; days = 31; break;
default: cout << "invalid month" << endl;
cout << "Calendar: " << month << ", " << year; break;
cout << "Sun Mon Tue Wed Thu Fri"; break;
if (month < 12 && month > 1)
{
int numDays, firstDay, days, day;
firstDay = (2 + numDays) % 7; firstDay;
for (day = 1; day <= days; day++)
{
if ((day + firstDay) % 7 == 0)
cout << endl;
}
}
}
}
return 0;
}
Comments
Leave a comment