stoneharry

Untitled

Sep 14th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1.  -- Guess I'll comment my script some too... Start up of the program
  2. print("Welcome to mah calc!")
  3. print("This calculator cna only do + and - ...")
  4.  
  5. function HandleCommand() -- functions must be declared before they are called, so moving functions up
  6.     print("Please input a number!")
  7.     local f = io.read()
  8.     print("Please insert command.")
  9.     local x = io.read()
  10.     print("Please insert second number")
  11.     local g = io.read()
  12.    
  13.     DoMath(f, x, g)
  14. end
  15.  
  16. function DoMath(one, two, three)
  17.     -- This will be called on startup. You want it to be called when you have handled a command. Moved to a function.
  18.     if two == "+" then
  19.         print("Your Input:" .. tostring( tonumber(one) + tonumber(three) )) -- you need to convert to numbers
  20.     elseif two == "-" then
  21.         print("Your answer is:" .. tostring( tonumber(one) - tonumber(three) ))
  22.     elseif one == "-1" then
  23.         print("Secret code found. Deploying nukes.")
  24.         running = false
  25.     end
  26. end
  27.  
  28. local running = true
  29. while running do
  30.     HandleCommand()
  31. end
Advertisement
Add Comment
Please, Sign In to add comment