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