通过键盘输入数字“1--7”,根据输入的数字,输出是星期几的英文。如:输入数字“1”,则输出 Monday。要求:用 switch 语句完成。
时间: 2023-05-19 16:01:31 浏览: 125
好的,以下是代码:
```
#include <iostream>
using namespace std;
int main() {
int day;
cout << "请输入数字 1-7:" << endl;
cin >> day;
switch (day) {
case 1:
cout << "Monday" << endl;
break;
case 2:
cout << "Tuesday" << endl;
break;
case 3:
cout << "Wednesday" << endl;
break;
case 4:
cout << "Thursday" << endl;
break;
case 5:
cout << "Friday" << endl;
break;
case 6:
cout << "Saturday" << endl;
break;
case 7:
cout << "Sunday" << endl;
break;
default:
cout << "输入错误,请输入数字 1-7" << endl;
break;
}
return 0;
}
```
希望能够帮到你!
阅读全文