嗨,我正在寻找RandNum生成一个介于2-10之间的数字,然后这个数字被从15中删除。
现在,每次执行程序时,从15 (PerseusHealth)中取走的数字是7。我如何解决这个问题,并使其成为随机的?
void desertpath()
{
int scorpianchoice; //the option the player chooses.
int Maxhit = 10; //Max hit the scorpian can do
int Minhit = 2; //Min hit the scorpian can do
int randNum = rand()%(Maxhit + Minhit) + Minhit;
int healthremaining = PerseusHealth - randNum; //health left in option1.
if(scorpianchoice == 1)
{
cout << "You run under the Scorpians Legs in hopes to escape " << endl;
cout << "You are hit by the scorpians Sting for " << randNum << " hp!";
cout << "You have " << healthremaining << "/15 HP Left!" << endl;
cout << "You escape the Scorpian but not without taking some damage" << endl;
}发布于 2015-04-10 03:44:12
使用srand初始化。
srand((unsigned)time(0));此外,我认为你没有正确地把括号放在:
int randNum = (rand()%(Maxhit - Minhit)) + Minhit; 发布于 2015-04-12 04:21:50
@ebad86答案顶部的澄清
https://stackoverflow.com/questions/29552901
复制相似问题