the output of code comes out in order in lua

print("operation to run? \n")
enter code here`enter code here`print("operation:")
result = io.read()

if result == ('')
then print("type in an operator! \n")
end

if result == "+" or "addition" then
print("what you want to add first? \n")
print("number:")
add1 = io.read()
print("what is your second number? \n")
print("number:")
add2 = io.read()
print(add1 + add2,"<--- ")
os.execute("PAUSE")
end

if result == "-" or "subtraction" then
    print("what you want to subtract first? \n")
print("number:")
sub1 = io.read()
print("what is your second number? \n")
print("number:")
sub2 = io.read()
print(sub1 - sub2,"<--- ")
os.execute("PAUSE")
end

if result == "*" or "x" or "multiplication" then
    print("what you want to multiply first? \n")
    print("number:")
    multi1 = io.read()
    print("what is your second number? \n")
    print("number:")
    multi2 = io.read()
    print(multi1 * multi2,"<--- ")
    os.execute("PAUSE")
end

if result == "/" or "divison" then
print("what you want to divide first? \n")
print("number:")
divide1 = io.read()
print("what is your second number? \n")
print("number:")
divide2 = io.read()
print(divide1 / divide2,"<--- ")
os.execute("PAUSE")
end

if result == "^" or "power" then
print("what you want to power first? \n")
print("number:")
power1 = io.read()
print("what is your second number? \n")
print("number:")
power2 = io.read()
print(power1 ^ power2,"<--- ")
os.execute("PAUSE")
end

i am trying to make a calucator on lua so the output comes out like this operation to run?

operation:

at this point, after entering anything, it moves to addition and after adding some numbers, it moves on into subtraction, after that is multiplication, and so on. how do i make it one operation at a time to make the program stop running after doing one operation

Upvotes: 0

Views: 66

Answers (1)

user2346921
user2346921

Reputation: 11

As luther said, you have to correct your comparisons. It seems you want something like:

if result == ('') then
    print("type in an operator! \n")
elseif result == "+" or result == "addition" then
-- skip
elseif result == "-" or result == "subtraction" then
-- skip
elseif result == "*" or result == "multiplication" then
-- skip
end

This way you also avoid testing again and again

Upvotes: 1

Related Questions