Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

adding a % of some variable

I'm now trying to get harlowe to add some % of the number on one of the variables. Say, there is a stock market where you can invest, and they will help you save or lose you money.

Something like this:
(set: $stock1savings to $stock1price + (random: %-10,%25))

Comments

  • edited June 2015
    As explained by this link, to calculate a percentage of a value you first multiple the value by the percent you want and then you divide that by 100.

    eg. You want to calculate twenty percent of three hundred:
    20% of 300   =>   (20 * 300) / 100   =>   6000 / 100   =>   60
    

    If you wanted to add that percentage to the original value, it would look something like the following:
    300 + ((20 * 300) / 100)   =>  300 + 60   =>  360
    

    Using your example:
    (set: $stock1savings to $stock1price + (((random: -10, 25) * $stock1price) / 100))
    
  • I figured out there could be a way to make it simpler, since when I add a % sign, it tells me I need something to its right.
Sign In or Register to comment.