Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculator()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("Please type your first number")
- term.setTextColor(colors.white)
- firstNum = read()
- numOneIsValid = tonumber(firstNum)
- if type(numOneIsValid) == "number" then
- term.setTextColor(colors.orange)
- print("Please type your second number")
- term.setTextColor(colors.white)
- secondNum = read()
- numTwoIsValid = tonumber(secondNum)
- if type(numTwoIsValid) == "number" then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("What would you like to do with these numbers?")
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- print("{Add} {Subtract} {Multiply} {Divide}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=5 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- local sum = (firstNum+secondNum)
- term.setTextColor(colors.lightBlue)
- print("The sum of your numbers is "..sum)
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- print("{Clear} {Exit}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=7 and yPos == 3) then
- calculator()
- elseif (xPos >=9 and xPos <=14 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- else
- calculator()
- end
- else
- calculator()
- end
- sleep(3.5)
- startScreen()
- elseif (xPos >=7 and xPos <=16 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- local diff = (firstNum-secondNum)
- term.setTextColor(colors.lightBlue)
- term.write("The difference of your numbers is "..diff)
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- print("{Clear} {Exit}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=7 and yPos == 3) then
- calculator()
- elseif (xPos >=9 and xPos <=14 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- else
- calculator()
- end
- else
- calculator()
- end
- elseif (xPos >=18 and xPos <=27 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- local product = (firstNum*secondNum)
- term.setTextColor(colors.lightBlue)
- term.write("The product of your two numbers is "..product)
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- print("{Clear} {Exit}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=7 and yPos == 3) then
- calculator()
- elseif (xPos >=9 and xPos <=14 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- else
- calculator()
- end
- else
- calculator()
- end
- elseif (xPos >=29 and xPos <=36 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- local quotient = (firstNum/secondNum)
- term.setTextColor(colors.lightBlue)
- term.write("The quotient of your two numbers is "..quotient)
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- print("{Clear} {Exit}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=7 and yPos == 3) then
- calculator()
- elseif (xPos >=9 and xPos <=14 and yPos == 3) then
- term.clear()
- term.setCursorPos(1,1)
- else
- calculator()
- end
- else
- calculator()
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.red)
- print("The Endermen are not amused!")
- sleep(3)
- calculator()
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.red)
- print("The Endermen are not amused!")
- sleep(3)
- calculator()
- end
- end
- calculator()
Advertisement
Add Comment
Please, Sign In to add comment