开发者社区> 问答> 正文

选项2正在运行另一个if语句的代码。

每当我运行第二种选择时,它就不会运行代码,我也不知道为什么。但如果选择了选项2,它将运行将要发生的事情。

do
{
    getline(cin, cont)

    cout << "1 hour has passed. There is " << (dist1 = dist1 - 3) << "km left" << endl;
    ran = rand() % 7;
    if (ran == 1)
    {
        troll(trollh);
        cout << "Option 1: Fight" << endl;
        cout << "Option 2: Run" << endl;
        ask(choice);
        if (choice == 1)
        {
            damageony = (rand() % 2) + 2;
            shealth = hhealth(damageony, shealth);
            damage = (rand() % 5) + slevel;
            whhealth(damage, trollh);

            cout << "You are fighting and this is what happened" << endl;
            cout << "You have " << shealth << "health left" << endl;
            cout << "You did " << damage << "damage to the troll" << endl;
            xpch(xp, damageony);
            stats(shealth, slevel, xp, scoins);
            ddeath(shealth);
            do
            {
                if (trollh >= 1)
                {
                    damageony = (rand() % 2) + 1;
                    shealth = hhealth(damageony, shealth);
                    damage = (rand() % 5) + slevel;
                    whhealth(damage, trollh);

                    cout << "You are fighting and this is what happened" << endl;
                    cout << "You have " << shealth << "health left" << endl;
                    cout << "You did " << damage << "damage to the troll" << endl;
                    xpch(xp, damageony);
                    stats(shealth, slevel, xp, scoins);
                    ddeath(shealth);
                }
            } while (trollh >= 1);
        }
        else 
        {
            cout << "You chose to run away and now there is " << (dist1 = dist1 + 1) << "km left" << endl;
        }
    }
} while (dist1 >= 41);

到底问题出在了哪里呢?

展开
收起
aqal5zs3gkqgc 2019-12-06 20:19:13 1089 0
1 条回答
写回答
取消 提交回答
  • 确保ASK接受一个引用参数,并且选择是一个int,而不是一个字符。这是因为char 1与int 1不一样。chars被抛入其ASCII代码的整数值中。

    2019-12-06 20:19:37
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
JS 语言在引擎级别的执行过程 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载