-3

我正在用 C++ 构建一个简单的骰子游戏,您可以在其中与计算机对战,在游戏开始之前您可以下注让我们说 100,如果您赢了,您应该赢得双倍 = 200,如果您输了,100 将从中提取您拥有的帐户

我有这些变量:

int bet = 0; 
int account = 0

我试图用这个来制作我所说的:

if (computer > rounds)
   {
    wcout<< "Im sorry the computer won this round you have this amount left on your account:" << account - bet << endl;
   }
   else if (player > rounds)
   {
    wcout<< "Gratz you won this round now you have:" << account + bet*2 << endl;
   }

它没有成功,我一直在试图找出原因,感谢任何帮助!

4

2 回答 2

2

您正在计算价值,但没有将其存储在任何地方。你正在寻找这个:

if (computer > rounds)
   {
    account -= bet;
    wcout<< "Im sorry the computer won this round you have this amount left on your account:" << account << endl;
   }
   else if (player > rounds)
   {
    account += 2 * bet;
    wcout<< "Gratz you won this round now you have:" << endl;
   }

鉴于这是一个相当基本的问题,您可能需要考虑选择一本好书

于 2013-10-07T19:40:31.130 回答
0

请注意以下行:

wcout<< "Gratz you won this round now you have:" << account + bet*2 << endl;

不修改account变量,只是读取并使用它的值以便account + bet*2显示。如果它被放置在一个循环中并且您想修改account,您应该这样做:

acount += bet * 2;
wcout<< "Gratz you won this round now you have:" << account << endl;
于 2013-10-07T19:41:11.077 回答