Advertisement
Too_Quataz

Calculator Program in Progress

Jun 2nd, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. function calculator()
  2.     while true do
  3.         print("What is the operation you want to act upon?")
  4.         op = read()
  5.         if op == "add" or "subtract" or "multiply" or "divide" then
  6.             print("What is the first number acted upon?")
  7.             num1 = tonumber(read())
  8.             print("and the second number?")
  9.             num2 = tonumber(read())
  10.             if op == "add" then
  11.                 result = num1 + num2
  12.                 print(result)
  13.             elseif op == "subtract" then
  14.                 result = num1 - num2
  15.                 print(result)
  16.             elseif op == "multiply" then
  17.                 result = num1 * num2
  18.                 print(result)
  19.             elseif op == "divide" then
  20.                 result = num1 / num2
  21.             end
  22.         elseif op == "exit" then
  23.             print("Are you sure you want to exit the calculator application?")
  24.             confirm = read()
  25.             if confirm == "yes" then
  26.                 break
  27.             end
  28.         end
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement