#include<iostream>
using namespace std;
int main(){
printf("执行计算开始?1:0\n");
int choice=-1;
while (choice != 0 && choice != 1) {//非0或非1
cout << "请输入数字0或1,以决定是否继续程序:" << ends;
while (!(cin >> choice))
{
cin.clear();
while (cin.get() != '\n')
{
continue;
}//跳过错误输入
cout << "请输入数字0或1,以决定是否继续程序:"<<ends;
}
}
cout<<"choice="<<choice<<endl;
}
要求输入数字遇到输入的是字符的情况处理
最新推荐文章于 2023-02-12 20:52:01 发布