C++之判断执行条件

写的一个程序,判断执行条件,满足则执行,不满足则重新输入。

#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;
}
发布了113 篇原创文章 · 获赞 283 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_32642107/article/details/105375657