Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you run a mathematical equation when the operator is a variable?

Asked by 10 years ago

So I am making a calculator and I have set it up so that the operator is one of four different operations. But i can not seem to figure out how to execute the equation while using a variable.

function execute_eqation()
    one = string1.Text
    two = string2.Text
    output.Text = one..op..two.." = "..one(tostring(op))two
    end
equals.MouseButton1Down:connect(execute_eqation)

1 answer

Log in to vote
0
Answered by
ZeroBits 142
10 years ago

this is how I did it for my homemade homework program (I was bored, and it gave me homework, not did it for me.)


function execute_eqation() one = string1.Text two = string2.Text if opchoice == 1 then output.Text = one .. "+" .. two .. "=" .. one + two elseif opchoice == 2 then output.Text = one .. "-" .. two .. "=" .. one - two elseif opchoice == 3 then output.Text = one .. "x" .. two .. "=" .. one * two elseif opchoice == 4 then output.Text = one .. "/" .. two .. "=" .. one / two end end equals.MouseButton1Down:connect(execute_eqation)

I know it's not what You wanted, but I honestly have no idea how to do it otherwise. just have it so it changes the opchoice value depending on which operator you click.

Ad

Answer this question