Categories > Exploiting > Scripts >
Help me Calculator
Posted
Hello I created a calculator and I started to make the script that will calculate the formula written in the script and here is the result. It works with 2 operator but when I calculate 15 + 5-20 + 3 it sends me 23 I have another version or I created a debug dessu se that it allows to see where is the problem. And the problem is that once it is 20 - 20 it finds 0 but does not register it in the variable. Could you help me with his please?
Script -->
local str = "5+15-20+3"
local target = string.byte("+")
local target2 = string.byte("-")
local target3 = string.byte("*")
local target4 = string.byte("/")
local v1 = 0
local x = 0
local nombre = {}
local operateur = {}
local Resultat = 0
for v = 1, #str do
if str:byte(v) == target or str:byte(v) == target2 or str:byte(v) == target3 or str:byte(v) == target4 then
table.insert(nombre, string.sub(str, v1+1, v-1))
v1 = v
x = x+1
if str:byte(v) == target then
table.insert(operateur, 1)
elseif str:byte(v) == target2 then
table.insert(operateur, 2)
elseif str:byte(v) == target3 then
table.insert(operateur, 3)
elseif str:byte(v) == target4 then
table.insert(operateur, 4)
end
end
end
table.insert(nombre, string.sub(str, v1+1, #str))
for c = 1,x,1 do
if Resultat == 0 then
if operateur[c] == 1 then
Resultat = nombre[c] + nombre[c+1]
elseif operateur[c] == 2 then
Resultat = nombre[c] - nombre[c+1]
elseif operateur[c] == 3 then
Resultat = nombre[c] * nombre[c+1]
elseif operateur[c] == 4 then
Resultat = nombre[c] / nombre[c+1]
end
else
if operateur[c] == 1 then
Resultat = Resultat + nombre[c+1]
elseif operateur[c] == 2 then
Resultat = Resultat - nombre[c+1]
elseif operateur[c] == 3 then
Resultat = Resultat * nombre[c+1]
elseif operateur[c] == 4 then
Resultat = Resultat / nombre[c+1]
end
end
end
Thanks in advance.
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post