Posted 31 March 2018 - 03:43 PM
So I've made a simple calculator for my terminal, get to it by typing calc and it asks enough information for simple addition, subtraction, multiplication, and division. However, if I want to do more equations I have to type calc after each one is done to do another, and I don't want to do that. I'd like to be able to go into the program so it asks what I want to do, and when it's done with that equation it asks for the next right away unless I tell it I want to exit the program, but I have no clue how to do that. The code I have already is below, any tips or advice?
local sprint = textutils.slowPrint
term.write("What process?: ")
eq = read()
term.write("Enter first number: ")
num1 = tonumber(read())
term.write("Enter second number: ")
num2 = tonumber(read())
print(Calculating)
sprint("...", 3)
if eq == "+" then
result = num1+num2
print(result)
end
if eq == "-" then
result = num1-num2
print(result)
end
if eq == "/" then
result = num1/num2
print(result)
end
if eq == "*" then
result = num1*num2
print(result)
end