Mouamle

Cal3

Feb 19th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. -- anything after two dashes is a comment, and wont be compiled.
  2. --[[ this is also a comment
  3. and so is this
  4. ]]--
  5.  
  6. --this tutorial will teach you the basics of the print() and read() functions, if statements, as well as some variable use and math operations.
  7.  
  8.  
  9. print("Do you want to add, subtract, multiply or divide?") -- this code displays the question within the quotation marks
  10. op = read() -- this code creates a variable called 'op', the read() function stalls the program to accept user input, which is stored in op
  11. print("") -- just gives us some space to work with
  12.  
  13. print("what is the first number to be operated on?")
  14.  
  15. num1 = tonumber(read()) -- accepts the first number to be stored in the variable 'number1'
  16. print("")
  17.  
  18. print("and the second number?")
  19. num2 = tonumber(read())
  20. print("")
  21.  
  22. -- now we operate on the number depending on what the user typed first
  23.  
  24. if op == "add" then -- if you need help with conditional statements, see this page: [1]
  25.  result = num1+num2
  26. print(result) -- this prints the result
  27. end
  28.  
  29. if op == "multiply" then
  30.  result = num1*num2 -- asterisk represents multiply
  31. print(result)
  32. end
  33.  
  34. if op == "divide" then
  35.  result = num1/num2
  36. print(result)
  37. end
  38.  
  39. if op == "subtract" then
  40.  result = num1-num2
  41. print(result)
  42. end
Add Comment
Please, Sign In to add comment