Advertisement
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
- mathf = 0
- maths = 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 mathf == 1 then
- char = 14
- if mathf == 1 then
- finished = true
- end
- end
- elseif mouseX == 10 and characters ~= 0 then
- if mouseY == 1 then
- if mathf == 0 then
- mathf = -1
- end
- elseif mouseY == 3 then
- -- if pos == 1 and math == 0 then
- -- math = -5
- if mathf == 0 then
- mathf = -2
- end
- elseif mouseY == 5 then
- if mathf == 0 then
- mathf = -3
- end
- elseif mouseY == 7 then
- if mathf == 0 then
- mathf = -4
- end
- end
- end
- if char >=0 or mathf < 0 then
- term.setCursorPos(pos, 9)
- if mathf < 0 and mathf ~= -5 then
- if mathf == -1 then
- print(add)
- maths = 1
- elseif mathf == -2 then
- print(subtract)
- maths = 2
- elseif mathf == -3 then
- print(multiply)
- maths = 3
- elseif mathf == -4 then
- print(divide)
- maths = 4
- end
- mathf = 1
- pos = pos + 2
- elseif math == -5 then
- print("-")
- negative = true
- mathf = 0
- char = 13
- elseif char >= 0 and char ~= 12 and char ~= 14 then
- print(char)
- characters = 1
- if mathf == 0 and negative == false then
- editnum1(char)
- elseif mathf == 1 and negative == false then
- editnum2(char)
- elseif mathf == 0 and negative == true then
- editnum1("-")
- negative = false
- finalnegative = true
- end
- elseif char == 12 and mathf == 0 then
- print(decimal)
- editnum1(".")
- elseif char == 12 and mathf == 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 and finalnum1*1 ~= 0 then
- for error = 1, 10 do
- print("ERROR!!!!!"..math.random(1, 999999))
- sleep(0.5)
- end
- error()
- elseif maths == 4 and finalnum2*1 == 0 and finalnum1*1 == 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 then
- if finalnum1*1 == 0 or finalnum2*1 == 0 then
- print("That's some tough math.")
- end
- elseif maths == 3 or maths == 4 then
- if finalnum1*1 == 1 or finalnum2*1 == 1 then
- print("That's some tough math.")
- end
- end
- fs.delete("/temp/calctemp")
- fs.delete("/temp/calctemp2")
- char = -24
- mathf = 0
- maths = 0
- term.setCursorPos(1, 12)
- print("Press enter to finish.")
- quit = read()
- shell.run("calculator")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement