当我的电脑积分达到 100 分时游戏还没有结束
很奇怪,我在这里用 C++ 编写了我的小猪游戏,一旦用户或计算机达到 100,他就赢了。但问题是,如果我继续滚动并且超过 100,我就不会获胜,除非我在到达那里后坚持下去。如果计算机在 80 到 100 左右接近 100,它就会说它赢了。我不明白这里发生了什么以及问题是什么?我做的一切都是对的!或者我错过了什么?
我该如何解决这个问题,一旦我达到 100 滚动或在用户端保持,它就会获胜,并且不会超过 100,所以如果我保持在 100+,它会告诉我我赢了。我怎样才能让计算机只有在实际达到或自动超过 100 时才获胜?
It is strange, I coded my pig game here in c++ which once the user or computer reaches 100 he wins. But the problem is if I keep rolling and I go past 100 I don't win unless I hold after I get there. And the computer if it gets close to 100 around 80 to 100 it will just say it wins. I don't understand whats going on here and what the problem is? I did everything right! Or am I missing something?
How can I fix this issue where once I reach 100 rolling or holding on the users end that it just wins and doesn't go past 100 so if I hold at 100+ it tells me I win. How can I go about making it so the computer only wins when it actually gets to 100 or past it automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您继续玩的测试应该是 AND 而不是 OR。
应该是
否则两者都需要超过 100 才会停止,而不仅仅是其中之一。
我没有寻找可能存在的任何其他错误,当我发现那个错误时我就停了下来。
Your test to continue play should be AND not OR.
should be
Otherwise both need to be over 100 before it will stop, not just one of them.
I didn't look for any other bugs which may be there, I stopped when I found that one.
您是否注意到分配给 continuePlay 的逻辑位于播放循环之外?
Did you notice that your logic that assigns to continuePlay is outside the play loop?
尝试这样:
并
进行更改:
if
条件已更改。If
条件if(( humanTotalScore < 100) && (computerTotalScore < 100))
已移至do-while
循环。因为每次有人玩时都必须更新。int computerTurn(int&computerTotalScore)
被更改,在某些地方使用computerScore
代替computerTotalScore
Try it this way :
and
changes made :
if
condition was altered due to flaw in logic.If
condition,if((humanTotalScore < 100) && (computerTotalScore < 100))
was moved into thedo-while
loop. Since it have to be updated each time anyone plays.int computerTurn(int& computerTotalScore)
was altered,In some placescomputerScore
was used instead ofcomputerTotalScore
而不是
有
instead of
have