Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1, 1)
- fs.makeDir("temp")
- createtemp = fs.open("/temp/calctemp", "w")
- createtemp.writeLine(" ")
- createtemp.close()
- createtemp2 = fs.open("/temp/calctemp2", "w")
- createtemp2.writeLine(" ")
- createtemp2.close()
- function editnum1(x)
- readline = fs.open("/temp/calctemp", "r")
- readnum1 = readline.readLine()
- readline.close()
- writenum1 = fs.open("/temp/calctemp", "w")
- writenum1.write(readnum1..x)
- writenum1.close()
- end
- function editnum2(y)
- readnum2 = fs.open("/temp/calctemp2", "r")
- tempnum2 = readnum2.readLine()
- readnum2.close()
- writenum2 = fs.open("/temp/calctemp2", "w")
- writenum2.write(tempnum2..y)
- writenum2.close()
- end
- term.setTextColor(colors.yellow)
- print("7 8 9 +")
- print(" ")
- print("4 5 6 -")
- print(" ")
- print("1 2 3 *")
- print(" ")
- print(". 0 = /")
- decimal = "."
- add = " + "
- subtract = " - "
- multiply = " * "
- divide = " / "
- finished = false
- math = 0
- pos = 1
- term.setTextColor(1)
- minus = "-"
- negative = false
- characters = 0
- repeat
- char = -5
- local event, button, mouseX, mouseY = os.pullEvent("mouse_click")
- if mouseX == 1 then
- if mouseY == 1 then
- char = 7
- elseif mouseY == 3 then
- char = 4
- elseif mouseY == 5 then
- char = 1
- elseif mouseY == 7 then
- char = 12
- end
- elseif mouseX == 4 then
- if mouseY == 1 then
- char = 8
- elseif mouseY == 3 then
- char = 5
- elseif mouseY == 5 then
- char = 2
- elseif mouseY == 7 then
- char = 0
- end
- elseif mouseX == 7 then
- if mouseY == 1 then
- char = 9
- elseif mouseY == 3 then
- char = 6
- elseif mouseY == 5 then
- char = 3
- elseif mouseY == 7 and math == 1 then
- char = 14
- if math == 1 then
- finished = true
- end
- end
- elseif mouseX == 10 and characters ~= 0 then
- if mouseY == 1 then
- if math == 0 then
- math = -1
- end
- elseif mouseY == 3 then
- -- if pos == 1 and math == 0 then
- -- math = -5
- if math == 0 then
- math = -2
- end
- elseif mouseY == 5 then
- if math == 0 then
- math = -3
- end
- elseif mouseY == 7 then
- if math == 0 then
- math = -4
- end
- end
- end
- if char >=0 or math < 0 then
- term.setCursorPos(pos, 9)
- if math < 0 and math ~= -5 then
- if math == -1 then
- print(add)
- maths = 1
- elseif math == -2 then
- print(subtract)
- maths = 2
- elseif math == -3 then
- print(multiply)
- maths = 3
- elseif math == -4 then
- print(divide)
- maths = 4
- end
- math = 1
- pos = pos + 2
- elseif math == -5 then
- print("-")
- negative = true
- math = 0
- char = 13
- elseif char >= 0 and char ~= 12 and char ~= 14 then
- print(char)
- characters = 1
- if math == 0 and negative == false then
- editnum1(char)
- elseif math == 1 and negative == false then
- editnum2(char)
- elseif math == 0 and negative == true then
- editnum1("-")
- negative = false
- finalnegative = true
- end
- elseif char == 12 and math == 0 then
- print(decimal)
- editnum1(".")
- elseif char == 12 and math == 1 then
- print(decimal)
- editnum2(".")
- elseif char == 14 then
- finished = true
- end
- pos = pos + 1
- end
- until finished == true
- finalread1 = fs.open("/temp/calctemp", "r")
- finalnum1 = finalread1.readLine()
- finalread1.close()
- finalread2 = fs.open("/temp/calctemp2", "r")
- finalnum2 = finalread2.readLine()
- finalread2.close()
- term.setCursorPos(1, 10)
- print("=")
- if finalnum1 == nil or finalnum1 == " " then
- print("Please input two numbers")
- error()
- end
- if finalnum2 == nil or finalnum2 == " " then
- print("Please input two numbers.")
- error()
- end
- if maths == 4 and finalnum2*1 == 0.0 and finalnum1*1 ~= 0 then
- for error = 1, 100 do
- print("ERROR!!!!!"..math.random(1, 999999))
- sleep(0.5)
- end
- error()
- elseif maths == 4 and finalnum2*1.0 == 0 and finalnum1*1 == 0.0 then
- print("Imagine that you have zero cookies and you split them evenly among zero friends. How many cookies does each person get? See? It doesn't make sense. And Cookie Monster is sad that there are no cookies, and you are sad that you have no friends.")
- error()
- end
- if maths == 1 then
- print(finalnum1 + finalnum2)
- elseif maths == 2 then
- print(finalnum1 - finalnum2)
- elseif maths == 3 then
- print(finalnum1 * finalnum2)
- elseif maths == 4 then
- print(finalnum1 / finalnum2)
- end
- if maths == 1 or maths == 2 and finalnum1*1.0 == 0 or finalnum2*1.0 == 0 then
- print("That's some tough math.")
- elseif maths == 3 or maths == 4 and finalnum1*1.0 == 1 or finalnum2*1.0 == 1 then
- print("That's some tough math.")
- end
- fs.delete("/temp/calctemp")
- fs.delete("/temp/calctemp2")
Add Comment
Please, Sign In to add comment