每当我运行第二种选择时,它就不会运行代码,我也不知道为什么。但如果选择了选项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);
到底问题出在了哪里呢?
确保ASK接受一个引用参数,并且选择是一个int,而不是一个字符。这是因为char 1与int 1不一样。chars被抛入其ASCII代码的整数值中。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。