0% found this document useful (0 votes)
4 views

task3.cpp

This C++ program prompts the user to enter a year and a month, then calculates and displays the number of days in that month for the given year. It accounts for leap years in February. The program uses a switch statement to handle each month and provides an error message for invalid month entries.

Uploaded by

pihed94366
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

task3.cpp

This C++ program prompts the user to enter a year and a month, then calculates and displays the number of days in that month for the given year. It accounts for leap years in February. The program uses a switch statement to handle each month and provides an error message for invalid month entries.

Uploaded by

pihed94366
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;

int main()
{
int y,m;
int a=31,b=30,c;
cout<<"Enter year: ";
cin>>y;
cout<<"Enter Month: ";
cin>>m;

switch(m)
{
case 1:
cout<<"The number of days in January "<<y <<"are"<<a<<endl;break;
case 2:
{
if(y%4 == 0 && y%100 != 0 || y%400 == 0)
{
c=29;
cout<<"The number of days in February "<<y<<" are
"<<c<<endl;
}
else
{
c= 28;
cout<<"The number of days in February "<<y<<" are
"<<c<<endl;
}
break;
}
case 3:
cout<<"The number of days in March "<<y << "are"<<a<<endl;break;
case 4:
cout<<"The number of days in April "<<y << "are"<<b<<endl;break;
case 5:
cout<<"The number of days in May "<<y << "are"<<a<<endl;break;
case 6:
cout<<"The number of days in June "<<y << "are"<<b<<endl;break;
case 7:
cout<<"The number of days in July "<<y << "are"<<a<<endl;break;
case 8:
cout<<"The number of days in August "<<y << "are"<<a<<endl;break;
case 9:
cout<<"The number of days in September "<<y <<
"are"<<b<<endl;break;
case 10:
cout<<"The number of days in October "<<y <<
"are"<<a<<endl;break;
case 11:
cout<<"The number of days in November "<<y <<
"are"<<b<<endl;break;
case 12:
cout<<"The number of days in December "<<y <<
"are"<<a<<endl;break;
default:
cout<<"Invalid Entry of Month";
}
}

You might also like