Advertisement
Guest User

calc

a guest
May 31st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 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.  
  12. if tonumber(num1) == nil or tonumber(num2) == nil or cop == false or input[4] ~= null then
  13.   print("Usage: calc %number1% %number2% %operator(+,-,*,/)%")
  14. elseif num2 == "0" and op == "/" then
  15.   print("Can't devide by 0")
  16. elseif input[4] ~= null then
  17.   print("To many arguments")
  18. else
  19.   write("Result: ")
  20.   if op == "+" then
  21.     print(num1 + num2)
  22.   elseif op == "-" then
  23.     print(num1 - num2)
  24.   elseif op == "*" then
  25.     print(num1 * num2)
  26.   else
  27.     print(num1 / num2)
  28.   end
  29.  
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement