Mathematics question
#1

How would I go about doing this? (Refer mostly to the tax = ... part)

pawn Код:
forward UpdatePlayTime( );
public UpdatePlayTime ( )
{
    for( new u; u < MAX_PLAYERS; u ++ )
    {
        if( plLoggedIn [ u ] == true )
        {
            plStats [ u ] [ TimePlayedMins ] ++;
           
            if( plStats [ u ] [ TimePlayedMins ] >= 60 )
            {
                // Payday!
                new
                    wage = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ],
                    tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
                                    // tag mismatch ^
                    str [ 128 ];
                   
                plStats [ u ] [ Money ] += wage;
                plStats [ u ] [ LumberjackWage ] = 0, plStats [ u ] [ QuarryworkerWage ] = 0, plStats [ u ] [ TimePlayedMins ] = 0;
                plStats [ u ] [ TimePlayedHours ] ++;
               
                format( str, 128, "* You have earned $%d this paycheck. $%d in taxes were taken out.", wage, tax );
                SendClientMessage( u, Colour_LimeGreen, str );
            }
        }
    }
    return true;
}
Reply
#2

What do you want to do ?
Reply
#3

Sorry if I didn't make myself clear.

pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
I'm trying to divide an integer (say... 2000 for example) by a float (0.07 in this example), and it's giving me a tag mismatch because I can't do that with standard math functions apparently.
Reply
#4

Try storing 0.07 in a variable.
Reply
#5

You have floatdiv function (for divide)
floadsub (for substract)
floatadd (for add)
floatmul (for multiply)
...
Reply
#6

i want to mention that dividing any number by another number smaller than 1, results in multiplying by a large number:
A=1 / 0.07
where 0.07, as divisor, is the same as using a multiplier of 14.2
A=1 * 14.2
so change
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
to
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] * 0.07,
or incase you want the base amount including taxes, then simply add the 100 percent base as 1.00 added to the tax rate float:
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] * 1.07,
... this way you avoid a "divsion by zero" error when (if?) your taxes are set to 0
Reply
#7

Hmmmmm...
I think rather than trying to keep the variable "tax" to an integer. It would not be better in this case to use as I said a floatdiv, then floatround to round the value and to keep "tax" as an integer ?

(Sorry for my bad english)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)