LITTLEBLACKDOG.COM Forum Index LITTLEBLACKDOG.COM

 
LWD LWD   FAQ FAQ   Memberlist Memberlist   Usergroups Usergroups   Active Topics Active Topics   Register Register  
  Profile Profile   Log in to check your private messages Log in to check your private messages   Log in Log in  
  Who is Online Who is Online   Image Gallery Image Gallery   Chat Chat   Search Search  
  LWDGear       LBDGear  

View next topic
View previous topic
Post new topic     Reply to topic   LITTLEBLACKDOG.COM Forum Index » Code Warriors
Author Message
West
Butt Sniffer
Butt Sniffer


Joined: 27 Mar 2003
Posts: 1821
Location: Stealthed

Post Posted: Thu Oct 23, 2003 6:23 am   Post subject: How to add ±0%~15% on a value with C++ Reply with quote Back to top  

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.

Code: Select all

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

_________________
View user's profile Send private message Send e-mail
West
Butt Sniffer
Butt Sniffer


Joined: 27 Mar 2003
Posts: 1821
Location: Stealthed

Post Posted: Thu Oct 23, 2003 6:29 am   Post subject: Reply with quote Back to top  

((rand()%16)+1)

_________________
View user's profile Send private message Send e-mail
T
Curmudgeon


Joined: 17 May 2001
Posts: 16184
Location: Airstrip One

Post Posted: Thu Oct 23, 2003 6:47 am   Post subject: Reply with quote Back to top  

((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.
View user's profile Send private message
West
Butt Sniffer
Butt Sniffer


Joined: 27 Mar 2003
Posts: 1821
Location: Stealthed

Post Posted: Thu Oct 23, 2003 6:57 am   Post subject: Reply with quote Back to top  

Thanks demon, thats alot easier.

_________________
View user's profile Send private message Send e-mail
T
Curmudgeon


Joined: 17 May 2001
Posts: 16184
Location: Airstrip One

Post Posted: Thu Oct 23, 2003 7:05 am   Post subject: Reply with quote Back to top  

No idea if I got the syntax right or not. I know zip about C and C++. Smile

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.
View user's profile Send private message
West
Butt Sniffer
Butt Sniffer


Joined: 27 Mar 2003
Posts: 1821
Location: Stealthed

Post Posted: Thu Oct 23, 2003 7:12 am   Post subject: Reply with quote Back to top  

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:

Code: Select all
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));

_________________
View user's profile Send private message Send e-mail
West
Butt Sniffer
Butt Sniffer


Joined: 27 Mar 2003
Posts: 1821
Location: Stealthed

Post Posted: Thu Oct 23, 2003 8:48 am   Post subject: Reply with quote Back to top  

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 user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic     Reply to topic

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!