Posted 26 November 2015 - 06:01 PM
so, i'm making a calculator. Simple. I think I have the symbol selection working and i have the input working.
my problem is when you hit the + sign, it just stops and returns you to basic input.
when you hit the - sign, it proceeds to the second step, then after telling it to calculate, it also, returns you to basic input
when you hit the / sign, it adds, then loops to the second number area again then crashes, same with *.
Could someone explain this? Would be great!
Code:
Thanks in advance!
my problem is when you hit the + sign, it just stops and returns you to basic input.
when you hit the - sign, it proceeds to the second step, then after telling it to calculate, it also, returns you to basic input
when you hit the / sign, it adds, then loops to the second number area again then crashes, same with *.
Could someone explain this? Would be great!
Code:
sin = 0
function menu(text, id)
if sin == id then
write("[ "..text.." ]")
else
write(" "..text.." ")
end
print""
end
term.clear()
term.setCursorPos(1,1)
print"Enter First Number"
write""
input = tonumber(read())
term.clear()
term.setCursorPos(1,1)
print"Select A Symbol"
while true do
term.setCursorPos(1,4)
menu("+", 0)
menu("-", 1)
menu("/", 2)
menu("*", 3)
local event, key = os.pullEvent("key")
if key == 208 then
if sin > 2 then
sin = sin - 2
else
sin = sin + 1
end
elseif key == 200 then
if sin < 1 then
sin = sin + 2
else
sin = sin - 1
end
elseif key == 28 then
if sin == 0 then
break
end
term.clear()
term.setCursorPos(1,1)
print"Enter Second Number"
write""
input2 = tonumber(read())
output = input2 + input
term.clear()
term.setCursorPos(1,1)
print(output.." Press Enter To Continue")
sleep(1)
if key == 28 then
term.clear()
term.setCursorPos(1,1)
end
if sin == 1 then
break
end
term.clear()
term.setCursorPos(1,1)
print"Enter Second Number"
write""
input2 = tonumber(read())
output = input2 - input
term.clear()
term.setCursorPos(1,1)
print(output.." Press Enter To Continue")
sleep(1)
if key == 28 then
term.clear()
term.setCursorPos(1,1)
end
if sin == 2 then
break
end
term.clear()
term.setCursorPos(1,1)
print"Enter Second Number"
write""
input2 = tonumber(read())
output = input2 / input
term.clear()
term.setCursorPos(1,1)
print(output.." Press Enter To Continue")
sleep(1)
if key == 28 then
term.clear()
term.setCursorPos(1,1)
end
if sin == 3 then
break
end
term.clear()
term.setCursorPos(1,1)
print"Enter Second Number"
write""
input2 = tonumber(read())
output = input2 * input
term.clear()
term.setCursorPos(1,1)
print(output.." Press Enter To Continue")
sleep(1)
if key == 28 then
term.clear()
term.setCursorPos(1,1)
end
end
end
Thanks in advance!
Edited on 26 November 2015 - 05:08 PM