Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = "0.5b"
- print("Welcome to calculator v"..version..". It's a basic text calculator")
- io.write("What calculate? \n>")
- text = io.read()
- num = 1
- word = {}
- for text in string.gmatch(text, "%S+") do
- word[num] = text
- num = num + 1
- end
- n = 3
- loop = true
- answ = word[1]
- while loop do
- if word[n - 1] == "+" then
- answ = answ + word[n]
- elseif word[n - 1] == "-" then
- answ = answ - word[n]
- elseif word[n - 1] == "/" then
- answ = answ / word[n]
- elseif word[n - 1] == "*" then
- answ = answ * word[n]
- end
- n = n + 2
- if #word < n then
- loop = false
- end
- end
- print(answ)
Advertisement
Add Comment
Please, Sign In to add comment