while((Status.health != 0) && (Wolves.health != 0) )
{
int playerAttack = Status.strength + hitPoints() + Rock.attack;
cout<< "This is the player attack" << playerAttack;
Wolves.health = Wolves.health - playerAttack;
cout << "This is the wolves health" << Wolves.health;
if (Wolves.health <= 0)
{
cout << "\nThe wolves are dead\n ";
}
int wolfAttack = Wolves.attack + hitPoints();
Status.health - wolfAttack;
if(Status.health <= 0)
{
gameOver();
}// print out of object health.
}
有人可以帮忙吗?
答案 0 :(得分:3)
比较
Wolves.health = Wolves.health - playerAttack;
VS
Status.health - wolfAttack;
注意有什么不同吗?
答案 1 :(得分:2)
您确定这是正确的:
Status.health - wolfAttack;
这实际上是无操作。也许你的意思是:
Status.health -= wolfAttack;
答案 2 :(得分:2)
嗯,我认为健康状况并不完全是0 - 因为你的情况只适用于!= 0 它应该大于0
while((Status.health&gt; 0)&amp;&amp;(Wolves.health&gt; 0)) ...
编辑:还缺少= John Dibling先发现
答案 3 :(得分:2)
= 0或&lt; = 0如果你的“health”变量是整数,你给出一个容错,例如: =(0.5)或&lt; =(0.5)等......
答案 4 :(得分:1)
最有可能两个值都不为零。这听起来很可能,因为你自己使用<=
条件。
答案 5 :(得分:1)
我认为你的价值是负值,我建议使用
while((Status.health > 0) && (Wolves.health > 0) )