This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
moo3oo3oo3's profile picture

Help on Calculator Program

Started by moo3oo3oo3, 01 March 2014 - 01:11 AM
moo3oo3oo3 #1
Posted 01 March 2014 - 02:11 AM
I created a calculator program and can't seem to find the problem. Every time I run the program, nothing happens. Instead it just goes to the next line waiting for a command.


function add()
result = num1 + num2
print("Answer: " .. result)
end
function subtract()
result = num1 - num2
print("Answer: " .. result)
end
function multiply()
result = num1 * num2
print("Answer: " .. result)
end
function divide()
result = num1 / num2
print("Answer: " .. result)
end
function compare()
if num1 > num2 then
print(num1 .. " is greater than " .. num2)
elseif num1 < num2 then
print(num1 .. " is less than " .. num2)
else
print(num1 .. " is equal to " .. num2)
end
a = 1
while a == 1 do
print("")
print("Would you like to +, -, /, *, compare, or cancel")
print("")
op = read()
print("")
if op == "cancel" then
print("Calculator Canceled")
sleep(2)
term.setCursorPos(1, 1)
term. clear()
end
print("First Number?")
num1 = tonumber(read())
print("")
print("Second Number?")
num2 = tonumber(read())
print("")
if op == "+" then
add()
end
if op == "-" then
subtract()
end
if op == "/" then
divide()
end
if op == "*" then
multiply()
end
if op == "compare" then
compare()
end
end
end
CometWolf #2
Posted 01 March 2014 - 09:17 AM
This is why you should use indentation… The main code is part of the compare function because your ends are missplaced. Also, use code tags please!