这可能是一个非常新手的问题,但我只是在练习C++的类,并且似乎无法在while循环结束时执行此操作以在布尔条件下结束。如何在while循环结束时执行此操作?
int main()
{
bool endgame = false;
string x;
int choice;
cout << "please choose the colour you want your bow to be:\n";
cin >> x;
Bow bow1(x);
do
{
cout << "please choose what you would like to do\n";
cout << "(1 draw bow\n(2 fire bow\n(3 end game";
cin >> choice;
if (choice == 1)
{
bow1.Draw();
}
else if (choice == 2)
{
bow1.Fire();
}
else
{
endgame = true;
}
}
while (choice > 0 || choice < 3 || endgame == true);
return 0;
}
基本逻辑。 **在阅读我的答案之前,先想想**,你会明白的。 – 2013-07-05 11:03:47
无限循环不会结束。 – devnull
除了其他答案,您希望在选择> 0 *和*选择<3时循环,而不是*或* –