C++ Program to display month name according to the month number using Switch Statement

/* C++ Program to display month name according to the month number using Switch Statement */
#include <iostream>
using namespace std;
int main() 
{
	int n;
   	cout <<"Month No : ";
   	cin >> n;
   	switch(n)
   	{
		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;
		default:
      			cout <<"Invalid Month number\nPlease try again ....\n";
      			break;
    	}
        return 0;
}

Output :
Month No : 10
October



Leave a comment