|
LITTLEBLACKDOG.COM
|
| Author |
Message |
West
Butt Sniffer


Joined: 27 Mar 2003 Posts: 1821
Location: Stealthed
|
Posted:
Thu Oct 23, 2003 6:23 am Post subject: How to add ±0%~15% on a value with C++ |
|
The value between 0 and 15 needs to be random and also wether its + or - needs to be random.
EDIT:
Hmm, after a bit of thought.
int HP;
int value = (rand()%16);
int switch = (rand()%1);
if (switch==1) then
{
HP == (HP/100)*(100+value);
}
else
{
HP == (HP/100)*(100-value);
}
I think that would work.
Grr, pissy CODE tags |
_________________
|
|
|
|
|
West
Butt Sniffer


Joined: 27 Mar 2003 Posts: 1821
Location: Stealthed
|
Posted:
Thu Oct 23, 2003 6:29 am Post subject: |
|
((rand()%16)+1) |
_________________
|
|
|
|
|
T
Curmudgeon

Joined: 17 May 2001 Posts: 16184
Location: Airstrip One
|
Posted:
Thu Oct 23, 2003 6:47 am Post subject: |
|
((rand()%30)-15) |
_________________ Got questions? Click here.
Still got questions? Click here, too.
affabletoaster, Akely, anglachel, blahpony, CMTG, EdisonRex, Elk, Equin, evilness, Fido, fathertyme, Goddess, Jaymac, je, jodygirl, KingKobra, Lycander, mally, Max, OhioArt2, perrito_blanco, Rover, Spot, sully_51, Superdwarf, the taz man, thriftyjack, twiztid, wrathiron, yiayia49
Would you like good music at a price that is right? CD Baby, baby.
You look like you need a monkey.
|
|
|
|
|
West
Butt Sniffer


Joined: 27 Mar 2003 Posts: 1821
Location: Stealthed
|
Posted:
Thu Oct 23, 2003 6:57 am Post subject: |
|
Thanks demon, thats alot easier. |
_________________
|
|
|
|
|
T
Curmudgeon

Joined: 17 May 2001 Posts: 16184
Location: Airstrip One
|
Posted:
Thu Oct 23, 2003 7:05 am Post subject: |
|
No idea if I got the syntax right or not. I know zip about C and C++.
The method is sound, though, even if I muffed the syntax. |
_________________ Got questions? Click here.
Still got questions? Click here, too.
affabletoaster, Akely, anglachel, blahpony, CMTG, EdisonRex, Elk, Equin, evilness, Fido, fathertyme, Goddess, Jaymac, je, jodygirl, KingKobra, Lycander, mally, Max, OhioArt2, perrito_blanco, Rover, Spot, sully_51, Superdwarf, the taz man, thriftyjack, twiztid, wrathiron, yiayia49
Would you like good music at a price that is right? CD Baby, baby.
You look like you need a monkey.
|
|
|
|
|
West
Butt Sniffer


Joined: 27 Mar 2003 Posts: 1821
Location: Stealthed
|
Posted:
Thu Oct 23, 2003 7:12 am Post subject: |
|
Yeah its good, It meant I could get rid of the -/+ switch that I had. Made my program a tinsy bit faster.
Now I just need to know why e_hp is getting assigned 0 after this:
random_value = ((rand()%30)-15);
while (random_value==0)
{
random_value = ((rand()%30)-15);
}
rand_att = (rand()%3);
e_hp = (((base + (rand_att*5))/100)*(100+random_value));
|
_________________
|
|
|
|
|
West
Butt Sniffer


Joined: 27 Mar 2003 Posts: 1821
Location: Stealthed
|
Posted:
Thu Oct 23, 2003 8:48 am Post subject: |
|
I found out why, and a right tricky little bastard it was as well.
base is an int value, and I have it in a calculation with a division. I -think- C++ caste (?) the float (which is less than 1) into an int which turned it to 0. The rest of the calculation incloves the zero also. So the whole statement was zero. |
_________________
|
|
|
|
|
|
|
|
|
View next topic
View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB
© 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours
Help us keep advertisements off this site. Donate today!
|
|