DiabolusNeil

CalcPlus v1.1 Lite

Oct 25th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. -- CalcPlus v1.1 Lite | Last Updated 10/26/2013
  2. -- Minimal Requirement: Normal Computer
  3. -- Written by DiabolusNeil
  4.  
  5. os.pullEvent = os.pullEventRaw
  6.  
  7. local num1, num2, func, answer, fault, run
  8. local empty = ""
  9. local version = "v1.1"
  10.  
  11. local function main()
  12.   term.clear()
  13.   term.setCursorPos(17,1)
  14.   print("CalcPlus "..version.." Lite")
  15.   term.setCursorPos(18,2)
  16.   print("By DiabolusNeil\n")
  17.   print("First number:")
  18.   print("Function:")
  19.   print("Second number:")
  20.   if answer ~= nil then
  21.     term.setCursorPos(1,18)
  22.     print("Last Answer: "..answer)
  23.   end
  24.   term.setCursorPos(15,4)
  25.   num1 = read()
  26.   term.setCursorPos(11,5)
  27.   func = read()
  28.   term.setCursorPos(16,6)
  29.   num2 = read()
  30.   print("")
  31.  
  32.   if num1 == "ans" then num1 = answer end
  33.   if num2 == "ans" then num2 = answer end
  34.  
  35.   if func == "+" then
  36.     answer = num1 + num2
  37.   elseif func == "-" then
  38.     answer = num1 - num2
  39.   elseif func == "*" then
  40.     answer = num1 * num2
  41.   elseif func == "/" then
  42.     answer = num1 / num2
  43.   elseif func == "^" then
  44.     answer = num1 ^ num2
  45.   elseif func == empty or num1 == empty or num2 == empty then
  46.     fault = "Missing information"
  47.   elseif type(num1) or type(num2) == string then
  48.     fault = "Invalid given information"
  49.   else
  50.     fault = "Invalid given information"
  51.   end
  52.  
  53.   if fault == nil then
  54.     print(num1.." "..func.." "..num2.." = "..answer)
  55.   else
  56.     print("ERROR: "..fault)
  57.   end
  58.  
  59.   print("")
  60.   sleep(0.5)
  61.   print("Do you want to make a new calculation?")
  62.   print("ENTER = Yes | Anything Else = No")
  63.   event, key = os.pullEvent("key")
  64.  
  65.   if key == 28 then
  66.     run = true
  67.   else
  68.     run = false
  69.   end
  70. end
  71.  
  72. -- Actual program
  73. run = true
  74. while run do
  75.   fault = nil
  76.   main()
  77. end
  78. term.clear()
  79. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment