Returning incorrect tax amount. (SS)
#1

pawn Код:
new tax = CalculateTax(totalpay, WageTaxPercentage);
    taxtotal = totalpay - tax;
pawn Код:
format(string, sizeof(string), "Total Tax Deduction at %.1f%%%%: $%d (Money Transferred to your bank account)",WageTaxPercentage, AddCommas(taxtotal));//line to display
    SendClientMessage(playerid, 0xFFFF90FF, string);
pawn Код:
CalculateTax(amount, Float:percentage)
    return (amount / 100) * (_:percentage);
Issue is it's returning incorrect calculation, check screenshot!
Reply
#2

Mhm.. Anymore information regarding this problem?
Reply
#3

Basically, if you check the screenshot you can see the issue, the tax rate should be 20%. What would you like to know?
Reply
#4

I made a biggest mistake about the _: it took me time to find out a really really simple problem! Anyways here's the fully tested code, it works perfectly and doesn't return and incorrect values.

pawn Код:
CalculateTax(args1, Float:args2)
{
    if(0.0 > args2 > 100.0 && args1 < 0) return false; //return false if args2 is above 100% and below 0% same as the args1.
    return _:(args1 / 100 * args2);
}
Example Code

pawn Код:
public OnGameModeInit()
{
    printf("Tax 10%% of 1,000 = %.2f", CalculateTax(1000, 5.0) );
    printf("Tax 10%% of 1,000 = %.2f", CalculateTax(1000, 10.0) );
    printf("Tax 15%% of 1,000 = %.2f", CalculateTax(1000, 15.0) );
    printf("Tax 20%% of 1,000 = %.2f", CalculateTax(1000, 20.0) );
    printf("Tax 25%% of 1,000 = %.2f", CalculateTax(1000, 25.0) );
    printf("Tax 30%% of 1,000 = %.2f", CalculateTax(1000, 30.0) );
    printf("Tax 35%% of 1,000 = %.2f", CalculateTax(1000, 35.0) );
    printf("Tax 40%% of 1,000 = %.2f", CalculateTax(1000, 40.0) );
    printf("Tax 45%% of 1,000 = %.2f", CalculateTax(1000, 45.0) );
    printf("Tax 50%% of 1,000 = %.2f", CalculateTax(1000, 50.0) );
    printf("Tax 55%% of 1,000 = %.2f", CalculateTax(1000, 55.0) );
    printf("Tax 60%% of 1,000 = %.2f", CalculateTax(1000, 60.0) );
    printf("Tax 65%% of 1,000 = %.2f", CalculateTax(1000, 65.0) );
    printf("Tax 70%% of 1,000 = %.2f", CalculateTax(1000, 70.0) );
    printf("Tax 75%% of 1,000 = %.2f", CalculateTax(1000, 75.0) );
    printf("Tax 80%% of 1,000 = %.2f", CalculateTax(1000, 80.0) );
    printf("Tax 85%% of 1,000 = %.2f", CalculateTax(1000, 85.0) );
    printf("Tax 90%% of 1,000 = %.2f", CalculateTax(1000, 90.0) );
    printf("Tax 95%% of 1,000 = %.2f", CalculateTax(1000, 95.0) );
    return true;
}

CalculateTax(args1, Float:args2)
{
    if(0.0 > args2 > 100.0 && args1 < 0) return false; //return false if args2 is above 100% and below 0% same as the args1.
    return _:(args1 / 100 * args2);
}


/*
[19:28:21] Tax 10% of 1,000 = 50.00
[19:28:21] Tax 10% of 1,000 = 100.00
[19:28:21] Tax 15% of 1,000 = 150.00
[19:28:21] Tax 20% of 1,000 = 200.00
[19:28:21] Tax 25% of 1,000 = 250.00
[19:28:21] Tax 30% of 1,000 = 300.00
[19:28:21] Tax 35% of 1,000 = 350.00
[19:28:21] Tax 40% of 1,000 = 400.00
[19:28:21] Tax 45% of 1,000 = 450.00
[19:28:21] Tax 50% of 1,000 = 500.00
[19:28:21] Tax 55% of 1,000 = 550.00
[19:28:21] Tax 60% of 1,000 = 600.00
[19:28:21] Tax 65% of 1,000 = 650.00
[19:28:21] Tax 70% of 1,000 = 700.00
[19:28:21] Tax 75% of 1,000 = 750.00
[19:28:21] Tax 80% of 1,000 = 800.00
[19:28:21] Tax 85% of 1,000 = 850.00
[19:28:21] Tax 90% of 1,000 = 900.00
[19:28:21] Tax 95% of 1,000 = 950.00
*/
PS: Try values like 93.55, I just tested the basic values and usually used
Reply
#5

Thank you ever so much Patrick. Really appreciate it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)