int main()
{
int in;
cout << "please enter a number between 1 and 70" << endl;
cin >> in;
string star = "*";
const int lessthan = in < 1;
const int greaterthan = in > 70;
while (true) {
if (lessthan || greaterthan) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "please enter a number between 1 and 70" << endl;
}
else {
for (int looptimes = 0; looptimes <=in ; ++looptimes) {
cout.width(looptimes);
cout << star << endl;
break;
}
}
}
}
基本上我只想弄清楚如何从输入正确时结束循环。此外,我希望能够在输入正确时停止询问。在while循环中使用,然后执行for循环一次cin为真
哇,这是一些丑陋的缩进。 – melpomene
出于好奇 - 为什么'star'是'string'而不是'char','lessthan'和'greaterthan'是'const int's而不是'const bool's? – Fureeish
谭的风格代码...我拒绝阅读。 – iBug