小编Dee*_*nce的帖子

C ++ OR运算符仅在第1部分为真时才拒绝停止

我一直在玩一些教程,并且到达了使用“ while”的位置,OR运算符仅在第一个条件为true时停止,而在第二个条件为true时才停止,即使第二个条件已经满足在某些循环中确实如此。

while (humanCount > 0 || skeletonCount > 0)
{
    cout << "Humans left: " << humanCount << " | Skeletons left: " << skeletonCount << "\n";
    if (currentTurn == 0) // Human Attack
    {
        if (rollChance(randomNum) >= 0.5f)
        {
            skeletonCurrentHealth -= rollDamage(randomNum);
            if (skeletonCurrentHealth <= 0)
            {
                skeletonCount--;
                skeletonCurrentHealth = skeletonMaxHealth;
            }
        }
        currentTurn = 1;
    }
    else // Skeleton Attack
    {
        if (rollChance(randomNum) >= 0.7f)
        {
            humanCurrentHealth -= rollDamage(randomNum);
            if (humanCurrentHealth <= 0)
            {
                humanCount--;
                humanCurrentHealth = …
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
2
解决办法
109
查看次数

标签 统计

c++ ×1