Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reset()
- term.clear()
- term.setCursorPos(1,1)
- end
- function frame()
- print("+-------------------------------------------------+")
- for i = 1,17 do
- print("| |")
- end
- term.write("+-------------------------------------------------+")
- end
- lastAnswer = false --I will be adding this back in later, it got delete when I re-coded everything :)
- while true do
- reset()
- term.setTextColor(colors.purple)
- frame()
- term.setCursorPos(4,1)
- term.setTextColor(colors.orange)
- io.write("[Back]")
- term.setCursorPos(19,1)
- term.setTextColor(colors.lime)
- io.write("[EnderCalc]")
- term.setCursorPos(3,3)
- io.write("{Add} {Subtract} {Multiply} {Divide} {Square}")
- term.setCursorPos(3,5)
- io.write("{Square Root} {Pythagorean Theorem} {x^y}")
- term.setCursorPos(3,7)
- io.write("{Generate A Random Number Between Two Numbers}")
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=3 and xPos <=7 and yPos ==3) then --ADD
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your first number?")
- term.setTextColor(colors.white)
- firstNum = read()
- valid = tonumber(firstNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #firstNum <= 8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your second number?")
- term.setTextColor(colors.white)
- secondNum = read()
- valid = tonumber(secondNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #secondNum <= 8
- sum = (firstNum+secondNum)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The sum of "..firstNum.." and "..secondNum.." is "..sum)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=9 and xPos <=18 and yPos ==3) then --SUBTRACT
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your first number?")
- term.setTextColor(colors.white)
- firstNum = read()
- valid = tonumber(firstNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #firstNum <= 8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your second number?")
- term.setTextColor(colors.white)
- secondNum = read()
- valid = tonumber(secondNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #secondNum <= 8
- diff = (firstNum-secondNum)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The difference between "..firstNum.." and "..secondNum.." is "..diff)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=20 and xPos <=29 and yPos ==3) then --MULTIPLY
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your first number?")
- term.setTextColor(colors.white)
- firstNum = read()
- valid = tonumber(firstNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #firstNum <= 8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your second number?")
- term.setTextColor(colors.white)
- secondNum = read()
- valid = tonumber(secondNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #secondNum <= 8
- diff = (firstNum*secondNum)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The product of "..firstNum.." and "..secondNum.." is "..diff)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=31 and xPos <=38 and yPos ==3) then --DIVIDE
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your first number?")
- term.setTextColor(colors.white)
- firstNum = read()
- valid = tonumber(firstNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #firstNum <= 8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your second number?")
- term.setTextColor(colors.white)
- secondNum = read()
- valid = tonumber(secondNum)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #secondNum <= 8
- diff = (firstNum/secondNum)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The quotient of "..firstNum.." and "..secondNum.." is "..diff)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=40 and xPos <=47 and yPos ==3) then --SQUARE
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What number would you like to square?")
- term.setTextColor(colors.white)
- sq = read()
- valid = tonumber(sq)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #sq <= 8
- square = (sq^2)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The square of "..sq.." is "..square)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=3 and xPos <=15 and yPos ==5) then --SQUARE ROOT
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What number do you need the square root of?")
- term.setTextColor(colors.white)
- sqRt = read()
- valid = tonumber(sqRt)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #sqRt <= 8
- squareRoot = math.sqrt(sqRt)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("The square of "..sqRt.." is "..squareRoot)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=17 and xPos <=37 and yPos ==5) then --PYTHAGOREAN THEOREM
- reset()
- term.setTextColor(colors.orange)
- print("What value are you missing?")
- term.setCursorPos(1,3)
- term.setTextColor(colors.lime)
- io.write("{a} {b} {c}")
- event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button == 1 then
- if (xPos >=1 and xPos <=3 and yPos == 3) then
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of b?")
- term.setTextColor(colors.white)
- b = read()
- valid = tonumber(b)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #b <=8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of c?")
- term.setTextColor(colors.white)
- c = read()
- valid = tonumber(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- sleep(0.1)
- if b >= c then
- term.setTextColor(colors.red)
- io.write("The leg(s) of a triangle cannot be greater or equal to the hypotenuse!")
- sleep(2.3)
- end
- until validNum == "number" and #c <=8 and b<c
- bSq = (b^2)
- cSq = (c^2)
- aSq = (cSq-bSq)
- a = math.sqrt(aSq)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("a = "..a.." b = "..b.." c = "..c)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=5 and xPos <=7 and yPos == 3) then
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of a?")
- term.setTextColor(colors.white)
- a = read()
- valid = tonumber(a)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #a <=8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of c?")
- term.setTextColor(colors.white)
- c = read()
- valid = tonumber(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- sleep(0.1)
- if a >= c then
- term.setTextColor(colors.red)
- io.write("The leg(s) of a triangle cannot be greater or equal to the hypotenuse!")
- sleep(2.3)
- end
- until validNum == "number" and #c <=8 and a<c
- aSq = (a^2)
- cSq = (c^2)
- bSq = (cSq-aSq)
- b = math.sqrt(bSq)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("a = "..a.." b = "..b.." c = "..c)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=9 and xPos <=11 and yPos == 3) then
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of a?")
- term.setTextColor(colors.white)
- a = read()
- valid = tonumber(a)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #a <=8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of b?")
- term.setTextColor(colors.white)
- b = read()
- valid = tonumber(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- sleep(0.1)
- until validNum == "number" and #b <=8
- aSq = (a^2)
- bSq = (b^2)
- cSq = (aSq+bSq)
- c = math.sqrt(cSq)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("a = "..a.." b = "..b.." c = "..c)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- end
- end
- elseif (xPos >=39 and xPos <=43 and yPos == 5) then
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of x?")
- term.setTextColor(colors.white)
- x = read()
- valid = tonumber(x)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #x <=8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is the value of y?")
- term.setTextColor(colors.white)
- y = read()
- valid = tonumber(y)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #y <=8
- xy = (x^y)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write(x.."^"..y.." equals "..xy)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- elseif (xPos >=3 and xPos <=48 and yPos == 7) then
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your first param/number?")
- term.setTextColor(colors.white)
- firstParam = read()
- valid = tonumber(firstParam)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- until validNum == "number" and #firstParam <=8
- repeat
- reset()
- term.setTextColor(colors.orange)
- print("What is your second param/number?")
- term.setTextColor(colors.white)
- secondParam = read()
- valid = tonumber(secondParam)
- validNum = type(valid)
- if validNum ~= "number" then
- term.setTextColor(colors.red)
- io.write("This is not a number...")
- sleep(2.3)
- end
- sleep(0.1)
- if secondParam == firstParam then
- term.setTextColor(colors.red)
- io.write("The Endermen substitute your answer with a response too harsh to repeat!")
- sleep(3.5)
- end
- until validNum == "number" and #secondParam <=8 and secondParam ~= firstParam
- rdm = math.random(firstParam,secondParam)
- reset()
- term.setTextColor(colors.lightBlue)
- io.write("A random number between "..firstParam.." and "..secondParam.." is "..rdm)
- term.setCursorPos(1,19)
- term.setTextColor(colors.orange)
- io.write("Press any key to continue")
- local event = os.pullEvent()
- if event == "key" then
- reset()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment