Advertisement
DiabolusNeil

CalcPlus v1.1

Oct 26th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. -- CalcPlus v1.1 | Last Updated 10/26/2013
  2. -- Minimal Requirement: Advanced 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.setTextColor(colors.red)
  14.   term.setCursorPos(19,1)
  15.   print("CalcPlus "..version)
  16.   term.setCursorPos(18,2)
  17.   print("By DiabolusNeil\n")
  18.   term.setTextColor(colors.green)
  19.   print("First number:")
  20.   print("Function:")
  21.   print("Second number:")
  22.   if answer ~= nil then
  23.     term.setCursorPos(1,18)
  24.     term.setTextColor(colors.red)
  25.     print("Last Answer: "..answer)
  26.   end
  27.   term.setTextColor(colors.yellow)
  28.   term.setCursorPos(15,4)
  29.   num1 = read()
  30.   term.setCursorPos(11,5)
  31.   func = read()
  32.   term.setCursorPos(16,6)
  33.   num2 = read()
  34.   print("")
  35.  
  36.   if num1 == "ans" then num1 = answer end
  37.   if num2 == "ans" then num2 = answer end
  38.  
  39.   if 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 == "/" then
  46.     answer = num1 / num2
  47.   elseif func == "^" then
  48.     answer = num1 ^ num2
  49.   elseif func == empty or num1 == empty or num2 == empty then
  50.     fault = "Missing information"
  51.   elseif type(num1) or type(num2) == string then
  52.     fault = "Invalid given information"
  53.   else
  54.     fault = "Invalid given information"
  55.   end
  56.  
  57.   if fault == nil then
  58.     term.setTextColor(colors.orange)
  59.     print(num1.." "..func.." "..num2.." = "..answer)
  60.   else
  61.     term.setTextColor(colors.red)
  62.     print("ERROR: "..fault)
  63.   end
  64.  
  65.   print("")
  66.   sleep(0.5)
  67.   term.setTextColor(colors.green)
  68.   print("Do you want to make a new calculation?")
  69.   print("ENTER = Yes | Anything Else = No")
  70.   event, key = os.pullEvent("key")
  71.  
  72.   if key == 28 then
  73.     run = true
  74.   else
  75.     run = false
  76.   end
  77. end
  78.  
  79. -- Actual program
  80. if not term.isColor() then
  81.   print("\nRequires an Advanced Computer\n")
  82. else
  83.   term.setBackgroundColor(colors.blue)
  84.   run = true
  85.   while run do
  86.     fault = nil
  87.     main()
  88.   end
  89.   term.setCursorPos(1,1)
  90.   term.setBackgroundColor(colors.black)
  91.   term.setTextColor(colors.white)
  92.   term.clear()
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement