【发布时间】:2014-06-26 08:06:39
【问题描述】:
我想要做的是问一个简单的问题,使用 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 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;
【问题讨论】:
标签: visual-c++ if-statement input while-loop