Write a C++ program to Show Season from Month 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 | #include <iostream> using namespace std; int main() { int month; cout << "Enter month number (1-12): "; cin >> month; switch (month) { case 12: case 1: case 2: cout << "Winter" << endl; break; case 3: case 4: case 5: cout << "Spring" << endl; break; case 6: case 7: case 8: cout << "Summer" << endl; break; case 9: case 10: case 11: cout << "Autumn" << endl; break; default: cout << "Invalid month number. Please enter a number between 1 and 12." << endl; break; } return 0; } |
Possible Outputs:
- Input:
1
- Output:
Winter
- Output:
- Input:
2
- Output:
Winter
- Output:
- Input:
3
- Output:
Spring
- Output:
- Input:
4
- Output:
Spring
- Output:
- Input:
5
- Output:
Spring
- Output:
- Input:
6
- Output:
Summer
- Output:
- Input:
7
- Output:
Summer
- Output:
- Input:
8
- Output:
Summer
- Output:
- Input:
9
- Output:
Autumn
- Output:
- Input:
10
- Output:
Autumn
- Output:
- Input:
11
- Output:
Autumn
- Output:
- Input:
12
- Output:
Winter
- Output:
- Input: Any number other than
1-12
(e.g.,13
)- Output:
Invalid month number. Please enter a number between 1 and 12.
- Output: