Introduction: In previous article i explained how to check the day corresponding to entered number using Else if ladder in C++ Language and How to swap two numbers without using temporary variable in C++ Language? and Check whether a number is positive or negative using if else in C++ Language and Check whether a number is even or odd using if else statement in C++ Language In this
article i am going to explain how to check the month name corresponding
to entered number using ladder else if or we can say multiple else if
in C++ language. Let's understand by creating a program.
#include<conio.h>
Third Run
#include<conio.h>
#include<iostream.h>
main()
{
cout<<"Enter any
number between 1 to 12 : ";
cin>>num;
if(num==1)
{
cout<<"JANUARY";
}
else if(num==2)
{
cout<<"FEBRUARY";
}
else if(num==3)
{
cout<<"MARCH";
}
else if(num==4)
{
cout<<"APRIL";
}
else if(num==5)
{
cout<<"MAY";
}
else if(num==6)
{
cout<<"JUNE";
}
else if(num==7)
{
cout<<"JULY";
}
else if(num==8)
{
cout<<"AUGUST";
}
else if(num==9)
{
cout<<"SEPTEMBER";
}
else if(num==10)
{
cout<<"OCTOBER";
}
else if(num==11)
{
cout<<"NOVEMBER";
}
else if(num==12)
{
cout<<"DECEMBER";
}
else
{
cout<<"INVALID NUMBER ...PLEASE ENTER NUMBER BETWEEN 1 TO 12";
}
getch();
}
Run the program using Ctrl+F9
Output:
First Run
Enter any number
between 1 to 12 : 8
AUGUST
Second Run
Enter any number between 1 to 12 : 10
OCTOBERThird Run
Enter any number between 1 to 12 : 15
INVALID NUMBER ...PLEASE ENTER NUMBER BETWEEN 1 TO 12
If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..