C++ 用每周的英文名称初始化一个字符指针数组,当键盘输入整数为1到7时,显示相应的周几,

输入其他整数时显示错误信息

第1个回答  2018-11-05
//#include "stdafx.h"//If the vc++6.0, with this line.
#include <iostream>
using namespace std;
int main(int argc,char *argv[]){
const char *s[10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int w;
cout << "Please w(int 1~7)...\nw=";
if(!(cin >> w) || w<1 || w>7){
cout << "Input error, exit...\n";
return 0;
}
cout << w << " --> " << s[w-1] << endl;
return 0;
}

运行样例:

本回答被网友采纳
相似回答