07.11.2016, 11:14
Hey!
so far I've only seen calculators script which can handle only 2 numbers!
But now you can calculate with multiple numbers.
Function in this include takes string and returning result as integer..
(soon as Float)
For now it works only with:
Function
compute[] - String which will be calculated
&result - Return result in this variable
&bool:fail - Return 'true' if is there any errors
failstring[] - Store error string
const len = sizeof(failstring)
From example:
will return
But this:
Script will remove empty letters and return:
return error:
=
=
(real calculator)
Example
Download:
https://github.com/Ino42O/PawnCalculator - 1.0.0
so far I've only seen calculators script which can handle only 2 numbers!
But now you can calculate with multiple numbers.
Function in this include takes string and returning result as integer..
(soon as Float)
For now it works only with:
Код:
Addition (+) Subtraction (−) Multiplication (Ч) Division (ч)
Код:
TryCalculate(compute[], &result, &bool:fail, failstring[], const len = sizeof(failstring));
&result - Return result in this variable
&bool:fail - Return 'true' if is there any errors
failstring[] - Store error string
const len = sizeof(failstring)
From example:
will return
But this:
Script will remove empty letters and return:
return error:
=
=
(real calculator)
Example
Код:
CMD:calculate(playerid, arg[]) { new compute[64], result, bool:fail, error[24], str[64] ; if (!sscanf(arg, "s[64]", compute)) { TryCalculate(compute, result, fail, error, sizeof(error)); if(!fail) { format (str, sizeof(str), "Calculated: %d", result); SendClientMessage(playerid, -1, str); } else { format (str, sizeof(str), "Calculate Error: %s", error); SendClientMessage(playerid, -1, str); } } else SendClientMessage(playerid, -1, "Usage: /calculate [anything]"); return 1; }
https://github.com/Ino42O/PawnCalculator - 1.0.0