它只是不断循环。数字继续减少,直到程序关闭。我在滥用什么吗?
playerHealth 和 orcHealth 整数为 100。
randomNumber = ("%10d", 1 + (rand() % 100));
这就是我看到 srand() 解释页面上使用的随机数的方式。如果这是错误的,应该怎么做?
这里还有其他问题吗?
switch(charDecision)
{
case 1:
cout << "FIGHT" << endl;
do{
randomNumber = ("%10d", 1 + (rand() % 100));
if(randomNumber >= 50){
orcHealth = orcHealth - (randomNumber - (randomNumber / 5));
cout << "You hit the orc! He now has " << orcHealth << " life left!" << endl;
}
else
{
playerHealth = playerHealth - (randomNumber - (randomNumber / 5));
cout << "The orc hit you! You now have " << playerHealth << " life left!" << endl;
}
}while(playerHealth || orcHealth >= 0);
break;
default:
break;
}