0
所以我在游戏的一个阶段创建了一个菜单。选择选项1或3后,你死了,你必须选择另一个,直到你选择选项2或4.之后,我的循环应该结束,让玩家按任何按钮,自动保存他的游戏,关闭程序,并在函数int main()转到游戏的另一部分,但在按2或4后,循环仍然有效,我可以永久按下这4个按钮。任何人都知道什么是错的?我的循环不想结束
cout<<tr("1. Option")<<endl;
cout<<tr("2. Option")<<endl;
cout<<tr("3. Option")<<endl;
cout<<tr("4. Option")<<endl;
while((wyborstage[2]!='2')||(wyborstage[2]!='4'))
{
wyborstage[2]=getch();
switch((wyborstage[2]))
{
case '1':
{
cout<<endl;
cout<<"Sample Text"<<endl<<endl;
cout<<"Try again"<<endl;
}
break;
case '2':
{
cout<<endl;
cout<<"Sample text"<endl;
}
break;
case '3':
{
cout<<endl;
cout<<"Sample text"<<endl;
cout<<tr("Try again")<<endl;
}
break;
case '4':
{
cout<<endl;
cout<<"Sample text"<<endl;
;
}
break;
default:
{
cout<<endl;
cout<<"Wrong answer"<<endl;
}
}
}
//End of this part of game
cout<<"Press any button to continue";
getch();
system("cls");
fstream save3;
save3.open("save.conf", ios::out);
save3<<3<<endl;
integ--;
对于这种情况,您应该使用do ... while循环 –
'((wyongstage [2]!='2')||(wyongstage [2]!='4'))'总是如此。我的意思是,如果'wyborstage [2] = 2'那么它不是4.如果'wyongstage [2] = 4'那么它不是2.如果'wyborstage [2] =任何其他值'那么它不是2或4. – drescherjm