http://www.computercraft.info/wiki/api.php?action=feedcontributions&user=85.113.254.5&feedformat=atom ComputerCraft Wiki - User contributions [en] 2022-06-26T01:36:04Z User contributions MediaWiki 1.24.1 http://www.computercraft.info/wiki/index.php?title=Calculator_Tutorial&diff=2330 Calculator Tutorial 2012-07-26T00:39:46Z <p>85.113.254.5: </p> <hr /> <div>&lt;code&gt;<br /> <br /> -- anything after two dashes is a comment, and wont be compiled.<br /> --[[ this is also a comment<br /> and so is this<br /> ]]--<br /> <br /> --this tutorial will teach you the basics of the print() and read() functions, if statements, as well as some variable use and math operations.<br /> <br /> <br /> print(&quot;Do you want to add, subtract, multiply or divide?&quot;) -- this code displays the question within the quotation marks<br /> op = read() -- this code creates a variable called 'op', the read() function stalls the program to accept user input, which is stored in op<br /> print(&quot;&quot;) -- just gives us some space to work with<br /> <br /> print(&quot;what is the first number to be operated on?&quot;)<br /> <br /> num1 = tonumber(read()) -- accepts the first number to be stored in the variable 'number1'<br /> print(&quot;&quot;)<br /> <br /> print(&quot;and the second number?&quot;)<br /> num2 = tonumber(read())<br /> print(&quot;&quot;)<br /> <br /> -- now we operate on the number depending on what the user typed first<br /> <br /> if op == &quot;add&quot; then -- if you need help with conditional statements, see this page: [http://www.troubleshooters.com/codecorn/lua/luaif.htm]<br /> result = num1+num2<br /> print(result) -- this prints the result<br /> end<br /> <br /> if op == &quot;multiply&quot; then<br /> result = num1*num2 -- asterisk represents multiply<br /> print(result)<br /> end<br /> <br /> if op == &quot;divide&quot; then<br /> result = num1/num2<br /> print(result)<br /> end<br /> <br /> if op == &quot;subtract&quot; then<br /> result = num1-num2<br /> print(result)<br /> end<br /> <br /> &lt;/code&gt;</div> 85.113.254.5