Author Topic: Calculating a Percentage  (Read 2696 times)

0 Members and 1 Guest are viewing this topic.

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Calculating a Percentage
« on: July 01, 2009, 12:39:16 AM »
0
Alright well I am trying to calculate a percentage of successful attempts but I can't seem to get it to work in any fashion....look at what I have here and see if there is a fix...if it is even possible....or something, it is begining to make me mad as I have tried a few variations and this was the one that I thought would work...unfortunatly it doesn't.

Code: [Select]
sub UpdateAttempt
  menu set EUOEdit3 %sucessattempts
  menu set EUOEdit4 %failedattempts
  set %totalattempts ( %sucessattempts + %failedattempts )
  set %percent ( %sucessattempts / %totalattempts )
  set %sucesspercent ( %percent * 100 )
  menu set EUOedit5 %sucesspercent
return

Offline rana70

  • Elite
  • *
  • *
  • Posts: 294
  • Activity:
    0%
  • Reputation Power: 5
  • rana70 has no influence.
  • Gender: Male
  • Respect: +37
  • Referrals: 2
    • View Profile
    • MyScripts
Re: Calculating a Percentage
« Reply #1 on: July 01, 2009, 01:45:36 AM »
0
Hi,

your line
Code: [Select]
set %percent ( %sucessattempts / %totalattempts )is the problem .... you will get always 0 out of it !

Reason:
you will everytime end up with more total attempts than sucess attempts,
in the best case (100%) you will have an equal amount !

So it is usually like Devide:less / more -> result is always 0.xxxxx
EUO cuts off everything behind the .


try this

Code: [Select]
For %i 1 20
{
 Set %sucessattempts ( 20 - %i )
 Set %failedattempts %i
 GoSUB Calculate
 Display Results:$ GoodAttempt: %sucessattempts FailedAttempts: %failedattempts Total: %totalattempts Prozent: %percent $

}
SUB Calculate
 set %totalattempts ( %sucessattempts + %failedattempts )
 Set %sucessattemptsExtended %sucessattempts * 100
 set %percent ( %sucessattemptsExtended / %totalattempts )
RETURN
halt

« Last Edit: July 01, 2009, 02:15:59 AM by rana70 »

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: Calculating a Percentage
« Reply #2 on: July 01, 2009, 05:20:17 AM »
0
That is what I figured was happening but didn't really know why....guess EUO just sucks at handling math that requires decimals, my whole assuming is that it would be 0.xxxxx and thus the reason I was mutiplying by 100 in the last line.  I will give the code you put together a try and see how she turns out when I get home this evening.

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Calculating a Percentage
« Reply #3 on: July 01, 2009, 05:40:38 AM »
0
I use percentages in my Taming Appraiser which your welcome to check out and use if you need.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Superslayer

  • Elite
  • *
  • *
  • Posts: 1006
  • Activity:
    0%
  • Reputation Power: 14
  • Superslayer barely matters.Superslayer barely matters.
  • Gender: Male
  • Well what do you drink? Not tea.
  • Respect: +43
  • Referrals: 0
    • View Profile
Re: Calculating a Percentage
« Reply #4 on: July 01, 2009, 12:21:21 PM »
0
Hi,

your line
Code: [Select]
set %percent ( %sucessattempts / %totalattempts )is the problem .... you will get always 0 out of it !

Reason:
you will everytime end up with more total attempts than sucess attempts,
in the best case (100%) you will have an equal amount !

So it is usually like Devide:less / more -> result is always 0.xxxxx
EUO cuts off everything behind the .


try this

Code: [Select]
For %i 1 20
{
 Set %sucessattempts ( 20 - %i )
 Set %failedattempts %i
 GoSUB Calculate
 Display Results:$ GoodAttempt: %sucessattempts FailedAttempts: %failedattempts Total: %totalattempts Prozent: %percent $

}
SUB Calculate
 set %totalattempts ( %sucessattempts + %failedattempts )
 Set %sucessattemptsExtended %sucessattempts * 100
 set %percent ( %sucessattemptsExtended / %totalattempts )
RETURN
halt



This is great Rana, TY. Mind if I use it in my WT script?
« Last Edit: July 01, 2009, 01:10:03 PM by Superslayer »

Offline KilroyIsDead

  • Full Member
  • ***
  • Posts: 155
  • Activity:
    0%
  • Reputation Power: 2
  • KilroyIsDead has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: Calculating a Percentage
« Reply #5 on: July 01, 2009, 12:49:06 PM »
0
Yeah I had a similar problem in trying to determine the hourly rates of resource gathering

Most of us all know it as...

GoodTries
---------- * 100
AllTries

Where we think divide first then multiply by 100 to get a percentage

But EUO only supports interger division so the first part 9/10 is reduced to an integer of 0 = GINT(9/10)

So if you multiply by 100 first then divide, it's mo better

This snippet shows teh bad way and teh good way, plus maybe you want to show tenths? or maybe you want to round?

Code: [Select]
set !Numerator 9876
set !Denominator 13789

set !Result !Numerator / !Denominator * 100
display ok !Result

set !Result 100 * !Numerator / !Denominator
display ok !Result

;For tenths multiply by an extra power of 10 (from 100 to 1000)
set !Result 1000 * !Numerator / !Denominator
display ok !Result
;add an decimal near the end
str len !Result
str ins !Result #dot #StrRES
set !Result #StrRES
display ok !Result , %

str right !Result 1
if #STRRES >= 5
{
  ;round up
  set !Result 100 * !Numerator / !Denominator + 1
}
else
{
  ;round down (GINT)
  set !Result 100 * !Numerator / !Denominator
}
display ok Which Rounds to: , #spc , !Result

halt


« Last Edit: July 01, 2009, 12:53:13 PM by KilroyIsDead »
Give a man a fire, he'll be warm the rest of the night;
Set a man afire, he'll be warm the rest of his life.

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: Calculating a Percentage
« Reply #6 on: July 01, 2009, 01:48:07 PM »
0
Rana, Thanks I didn't use your code exactly but I did use your math calculations to get what I needed ;)  Here's the code for those that might be interested.  I am adding to the %sucessattempts and the %failedattempts earlier in the script and in this portion I am just updating the menu.

Code: [Select]
sub UpdateAttempt
  menu set EUOEdit3 %sucessattempts
  menu set EUOEdit4 %failedattempts
  set %totalattempts ( %sucessattempts + %failedattempts )
  set %percent ( %sucessattempts / %totalattempts )
  set %sucesspercent ( %percent * 100 )
  menu set EUOedit5 %totalattempts
return

Offline rana70

  • Elite
  • *
  • *
  • Posts: 294
  • Activity:
    0%
  • Reputation Power: 5
  • rana70 has no influence.
  • Gender: Male
  • Respect: +37
  • Referrals: 2
    • View Profile
    • MyScripts
Re: Calculating a Percentage
« Reply #7 on: July 02, 2009, 12:57:24 AM »
0
Hi,

the important thing is you got your problem solved ....  ;)

cu

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: Calculating a Percentage
« Reply #8 on: July 02, 2009, 06:07:43 AM »
0
Werd

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Calculating a Percentage
« Reply #9 on: July 02, 2009, 06:12:13 AM »
0
For maximum accuracy... you should multiply your numbers by 100 before you divide them. Then when you divide them you'll get a more accurate percentage. It's because EUO has troubles with decimals.

If you look in my taming appraiser, there's a sub to get 2 decimal places when dividing.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Tags: