输入月份,输出月份所对应的季节
#include <iostream>
using namespace std;
void getSeason(unsigned int num)
{
switch(num)
{
case 1:
case 2:
case 3:
cout << "we in spring" << endl;
break;
case 4:
case 5:
case 6:
cout << "we in summer" << endl;
break;
case 7:
case 8:
case 9:
cout << "we in autumn" << endl;
break;
case 10:
case 11:
case 12:
cout << "we in winter" << endl;
break;
default:
cout << "you are in the black hole" << endl;
break;
}
}
int main()
{
unsigned int month = 13;
getSeason(month);
}
注意如果缺少了 break语句,程序会继续向下执行,直至遇到break