Visual c++ C++;与用户重复查询';s输入
我试着问一个简单的问题,用1或2作为输入的是或否。如果他们说1或2,那么代码将继续。但是如果他们说一个数字(7)或字符('q'),那么这个问题会再次重复。我还不知道如何重复问题和输入。 这就是我到目前为止所做的:Visual c++ C++;与用户重复查询';s输入,visual-c++,if-statement,input,while-loop,Visual C++,If Statement,Input,While Loop,我试着问一个简单的问题,用1或2作为输入的是或否。如果他们说1或2,那么代码将继续。但是如果他们说一个数字(7)或字符('q'),那么这个问题会再次重复。我还不知道如何重复问题和输入。 这就是我到目前为止所做的: #include "stdafx.h" #include <iostream> using namespace std; int main() { int answer = 0; do { cout << "Are you Bald? Yes(1) or N
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int answer = 0;
do
{
cout << "Are you Bald? Yes(1) or No(2)?" << endl;
cin >> answer; cout << endl;
if (answer == 1)
{
cout << "You Are Bald." << endl;
}
else if (answer == 2)
{
cout << "You are not bald." << endl;
}
else { cout << "Please Input proper answer" << endl << endl;
} while (answer < 1, answer > 2);
system("pause");
return 0;
#包括“stdafx.h”
#包括
使用名称空间std;
int main()
{
int-answer=0;
做
{
无法回答;无法尝试以下方法:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int answer = 0;
while(1)
{
cout << "Are you Bald? Yes(1) or No(2)?" << endl;
cin >> answer; cout << endl;
if (answer == 1)
{
cout << "You Are Bald." << endl;
break;
}
else if (answer == 2)
{
cout << "You are not bald." << endl;
break;
}
else
{
cout << "Please Input proper answer" << endl << endl;
}
}
return 0;
}
#包括“stdafx.h”
#包括
使用名称空间std;
int main()
{
int-answer=0;
而(1)
{
无法回答;我是否尝试过这个问题,但即使输入了1或2,它也会重复这个问题。