Advertisement
Guest User

calc

a guest
May 31st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. local input = {...}
  2. local num1 = input[1]
  3. local num2 = input[2]
  4. local op = input[3]
  5. local cop = false
  6.  
  7. if op == "+" or op == "-" or op == "*" or op == "/" then
  8.   cop = true
  9. end
  10.  
  11. if tonumber(num1) == nil or tonumber(num2) == nil or cop == false or input[4] ~= null then
  12.   print("Usage: calc %number1% %number2% %operator(+,-,*,/)%")
  13. elseif num2 == "0" and op == "/" then
  14.   print("Can't devide by 0")
  15. else
  16.   write("Result: ")
  17.   if op == "+" then
  18.     print(num1 + num2)
  19.   elseif op == "-" then
  20.     print(num1 - num2)
  21.   elseif op == "*" then
  22.     print(num1 * num2)
  23.   else
  24.     print(num1 / num2)
  25.   end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement