写的一个程序,判断执行条件,满足则执行,不满足则重新输入。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
void test01() {
int name;
cout << "请输入某个值:" << endl;
while (true) {
cin >> name;
if (name>0&&name<11) {
cout << "输入的值为正确值!" << endl;
break;
}
cout << "输入的值不正确,请重新输入!" << endl;
//cout << "标志位1:" << cin.fail() << endl;
cin.clear();
cin.sync();
//cout << "标志位2:" << cin.fail() << endl;
}
}
int main() {
test01();
system("pause");
return EXIT_SUCCESS;
}