Raised This Month: $32 Target: $400
 8% 

Question about percentage calculation.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-07-2012 , 10:42   Question about percentage calculation.
Reply With Quote #1

Hello, I want to make a HUD message which looks like that:

>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<

I have 2 variables, but I can't think of how exactly I can do it to show the percent of each variable (depending on the sum of them).
I have tried different ways buy I couldn't do it exactly as I want.

When they have the same value, then it should be 50%-50% and the HUD should look like the one above.

When they are 75%-50% the HUD should look like:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<

When they are 100%-0% it should be:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

99%-1%:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><

And so on...

The HUD must be always 40 characters.
The variables are integer numbers.

How exactly can I do this?
__________________

Last edited by <VeCo>; 05-07-2012 at 10:48.
<VeCo> is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-07-2012 , 10:59   Re: Question about percentage calculation.
Reply With Quote #2

You can do this:

Code:
GetHudBar(percent, output[], output_len, size = 40) {     new left_len = size * percent / 100;         new p;     while(p < output_len && p < left_len) {         output[p++] = '>';     }         while(p < output_len && p < size) {         output[p++] = '<';     }         output[p] = EOS;         return p; }

Usage:
Code:
new bar[41]; // 40 characters + 0 terminator GetHudBar(50, bar, charsmax(bar)); // should produce // >>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-07-2012 , 11:50   Re: Question about percentage calculation.
Reply With Quote #3

Thank you!
I also had a problem with the percent calculation, but I solved it...
__________________

Last edited by <VeCo>; 05-07-2012 at 11:51.
<VeCo> is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode