CPP
using namespace std;
int main()
{
int month;
cout << "Enter month number (1-12):\n";
cin >> month;
if(month == 1)
{
cout << "Month is : January " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 2)
{
cout << "Month is : February " <<endl;
cout << "No. of days : 28 or 29" <<endl;
}
else if(month == 3)
{
cout << "Month is : March " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 4)
{
cout << "Month is : April " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 5)
{
cout << "Month is : May " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 6)
{
cout << "Month is : June " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 7)
{
cout << "Month is : July " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 8)
{
cout << "Month is : August " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 9)
{
cout << "Month is : September " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 10)
{
cout << "Month is : October " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 11)
{
cout << "Month is : November " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 12)
{
cout << "Month is : December " <<endl;
cout << "No. of days : 31" <<endl;
}
else
{
cout << "Invalid input! Enter month number between (1-12).";
}
return 0;
}
Display the Name of Month with Day in C++
06 July
0
Write a program (WAP) in C++ to display the name of month with total days of month(if...else if).
#include<iostream>using namespace std;
int main()
{
int month;
cout << "Enter month number (1-12):\n";
cin >> month;
if(month == 1)
{
cout << "Month is : January " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 2)
{
cout << "Month is : February " <<endl;
cout << "No. of days : 28 or 29" <<endl;
}
else if(month == 3)
{
cout << "Month is : March " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 4)
{
cout << "Month is : April " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 5)
{
cout << "Month is : May " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 6)
{
cout << "Month is : June " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 7)
{
cout << "Month is : July " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 8)
{
cout << "Month is : August " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 9)
{
cout << "Month is : September " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 10)
{
cout << "Month is : October " <<endl;
cout << "No. of days : 31" <<endl;
}
else if(month == 11)
{
cout << "Month is : November " <<endl;
cout << "No. of days : 30" <<endl;
}
else if(month == 12)
{
cout << "Month is : December " <<endl;
cout << "No. of days : 31" <<endl;
}
else
{
cout << "Invalid input! Enter month number between (1-12).";
}
return 0;
}
Must Read :-
Previous article
Next article
Leave Comments
Post a Comment