64,683
社区成员
发帖
与我相关
我的任务
分享
int main()
{
char ch;
do{
ch = getchar();
getchar();
switch(ch)
{
case '1':
cout < < "1" < < endl;
break;
case '2':
cout < < "2" < < endl;
break;
default:
cout < < "ot" < < endl;
break;
}
}while(ch == '1' || ch == '2');
getchar();
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i;
do{
cout<<"input a interger(1-2):"<<endl;
cin>>i;
cin.ignore();//清空缓冲区用的是这个,cin.clear()是恢复IO
switch(i)
{
case 1:
cout<<"1"<<endl;
break;
case 2:
cout<<"2"<<endl;
break;
default:
cout<<"ot"<<endl;
break;
}
}while(i!=1 && i!=2);
return 0;
}