pickar

Calculator

Jun 9th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. version = "0.5b"
  2. print("Welcome to calculator v"..version..". It's a basic text calculator")
  3. io.write("What calculate? \n>")
  4.  
  5. text = io.read()
  6. num = 1
  7. word = {}
  8.  
  9. for text in string.gmatch(text, "%S+") do
  10.   word[num] = text
  11.   num = num + 1
  12. end
  13.  
  14. n = 3
  15. loop = true
  16. answ = word[1]
  17.  
  18. while loop do
  19.   if word[n - 1] == "+" then
  20.     answ = answ + word[n]
  21.   elseif word[n - 1] == "-" then
  22.     answ = answ - word[n]
  23.   elseif word[n - 1] == "/" then
  24.     answ = answ / word[n]
  25.   elseif word[n - 1] == "*" then
  26.     answ = answ * word[n]
  27.   end
  28.   n = n + 2
  29.   if #word < n then
  30.     loop = false
  31.   end
  32. end
  33.  
  34. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment