Advertisement
Guest User

calculateBetter

a guest
Mar 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. --please put operations in order
  2. args = {...}
  3. if args[1] == "ans" then
  4. args = {...}
  5. lastAnswer = fs.open("Ans","r")
  6. args[1] = lastAnswer.readAll()
  7. lastAnswer.close()
  8. end
  9. symbol = {}
  10. beforeSymbol = {args[1]}
  11. afterSymbol = {}
  12. for i=1,#args do
  13.  if (args[i] == "+") or (args[i] == "-") or (args[i] == "/") or (args[i] == "*") then
  14.   table.insert(symbol,args[i])
  15.   table.insert(afterSymbol,args[i+1])
  16.  end
  17. end
  18. output = beforeSymbol[1]
  19. for a=1,#symbol do
  20.  if symbol[a] == "+" then
  21.   output = output+afterSymbol[a]
  22.  elseif symbol[a] == "-" then
  23.   output = output-afterSymbol[a]
  24.  elseif symbol[a] == "/" then
  25.   output = output/afterSymbol[a]
  26.  elseif symbol[a] == "*" then
  27.  output = output*afterSymbol[a]
  28.  end
  29. end
  30. print(output)
  31. lastAnswer = fs.open("Ans","w")
  32. lastAnswer.write(output)
  33. lastAnswer.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement