Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CalcPlus v1.1 | Last Updated 10/26/2013
- -- Minimal Requirement: Advanced Computer
- -- Written by DiabolusNeil
- os.pullEvent = os.pullEventRaw
- local num1, num2, func, answer, fault, run
- local empty = ""
- local version = "v1.1"
- local function main()
- term.clear()
- term.setTextColor(colors.red)
- term.setCursorPos(19,1)
- print("CalcPlus "..version)
- term.setCursorPos(18,2)
- print("By DiabolusNeil\n")
- term.setTextColor(colors.green)
- print("First number:")
- print("Function:")
- print("Second number:")
- if answer ~= nil then
- term.setCursorPos(1,18)
- term.setTextColor(colors.red)
- print("Last Answer: "..answer)
- end
- term.setTextColor(colors.yellow)
- term.setCursorPos(15,4)
- num1 = read()
- term.setCursorPos(11,5)
- func = read()
- term.setCursorPos(16,6)
- num2 = read()
- print("")
- if num1 == "ans" then num1 = answer end
- if num2 == "ans" then num2 = answer end
- if func == "+" then
- answer = num1 + num2
- elseif func == "-" then
- answer = num1 - num2
- elseif func == "*" then
- answer = num1 * num2
- elseif func == "/" then
- answer = num1 / num2
- elseif func == "^" then
- answer = num1 ^ num2
- elseif func == empty or num1 == empty or num2 == empty then
- fault = "Missing information"
- elseif type(num1) or type(num2) == string then
- fault = "Invalid given information"
- else
- fault = "Invalid given information"
- end
- if fault == nil then
- term.setTextColor(colors.orange)
- print(num1.." "..func.." "..num2.." = "..answer)
- else
- term.setTextColor(colors.red)
- print("ERROR: "..fault)
- end
- print("")
- sleep(0.5)
- term.setTextColor(colors.green)
- print("Do you want to make a new calculation?")
- print("ENTER = Yes | Anything Else = No")
- event, key = os.pullEvent("key")
- if key == 28 then
- run = true
- else
- run = false
- end
- end
- -- Actual program
- if not term.isColor() then
- print("\nRequires an Advanced Computer\n")
- else
- term.setBackgroundColor(colors.blue)
- run = true
- while run do
- fault = nil
- main()
- end
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement