Write a C++ program to Show Month Name from Number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <iostream> using namespace std; int main() { int month; cout << "Enter month number (1-12): "; cin >> month; switch (month) { case 1: cout << "January" << endl; break; case 2: cout << "February" << endl; break; case 3: cout << "March" << endl; break; case 4: cout << "April" << endl; break; case 5: cout << "May" << endl; break; case 6: cout << "June" << endl; break; case 7: cout << "July" << endl; break; case 8: cout << "August" << endl; break; case 9: cout << "September" << endl; break; case 10: cout << "October" << endl; break; case 11: cout << "November" << endl; break; case 12: cout << "December" << endl; break; default: cout << "Invalid month number. Please enter a number between 1 and 12." << endl; break; } return 0; } |
Possible Outputs:
- Input:
1
- Output:
January
- Output:
- Input:
2
- Output:
February
- Output:
- Input:
3
- Output:
March
- Output:
- Input:
4
- Output:
April
- Output:
- Input:
5
- Output:
May
- Output:
- Input:
6
- Output:
June
- Output:
- Input:
7
- Output:
July
- Output:
- Input:
8
- Output:
August
- Output:
- Input:
9
- Output:
September
- Output:
- Input:
10
- Output:
October
- Output:
- Input:
11
- Output:
November
- Output:
- Input:
12
- Output:
December
- Output:
- Input: Any number other than
1-12
(e.g.,13
)- Output:
Invalid month number. Please enter a number between 1 and 12.
- Output: