Difference between revisions of "Calculator Tutorial"

From ComputerCraft Wiki
Jump to: navigation, search
Line 1: Line 1:
add = "add"
+
------- is what that string does
  
subtract = "subtract"
+
add = "add" ------ it says when i tell it to add then it codes it to the word add
  
multiply = "multiply"
+
subtract = "subtract" ------ the same as for add just with subtract
  
devide = "devide"
+
multiply = "multiply" ------ same as for add just with multiply
  
print ("Do you want to add, subtract, multiply or devide?")
+
devide = "devide" ------ sameas for add just for devide
  
write ("")
+
print ("Do you want to add, subtract, multiply or devide?") ------- prints the message written between (" and ")
  
put = io.read()
+
write ("") ------- makes room for you to write if you want add, subtract, multiply or devide.
  
write ("Enter your first number: ")
+
put = io.read() ------ reads what you write and codes it in to the word "put"
  
input = io.read()
+
write ("Enter your first number: ") ------ makes room for you to write your first number.
  
write ("Enter your second number: ")
+
input = io.read() ------ reads what you write above and codes it in to the word "input"
  
output = io.read()
+
write ("Enter your second number: ") -------- makes room for you to write the second number.
  
if put == add then
+
output = io.read() ------- reads what you write above and codes it into the word "output"
  
x = input + output
+
if put == add ------ then checks if the word you wrote when you chose if you wanted to add, subtract, multiply or devide then it checks if its the same as add, if its not thn it does nothing
  
print ("That = ", x)
+
x = input + output ------- if the word you wrote was the same as add then this adds the first number (input) and the second number (output) and then codes it into the letter x
  
elseif put == subtract then
+
print ("That = ", x) ------- prints That = (and then what x is)
  
x = input - output
+
elseif put == subtract then ------- if its not add that you wrote then this checks if its subtract
  
print ("That = ", x)
+
x = input - output -------- if it was subtract then this subtracts the input from the output and codes it into the letter x
  
elseif put == multiply then
+
print ("That = ", x) ------- the same as for add
  
x = input * output
+
elseif put == multiply then ------- if its not add or subtract you wrote then it checks if its multiply
  
print ("That = ", x)
+
x = input * output ------- if it is it multiplies input and output and codes it into the letter x
  
elseif put == devide then
+
print ("That = ", x)------ the same as for add
  
x = input / output
+
elseif put == devide then -------- if its not add, subtract or multiply you wrote then this checks if its devide
  
print ("That = ", x)
+
x = input / output ------- this devides input from output and codes them into the letter x
  
end
+
print ("That = ", x) ------- the same as for add
  
sleep(2)
+
end ------ since we only got  if then we only need 1 end
  
term.clear()
+
sleep(3) ------- waits 3 seconds before executing the next string
  
term.setCursorPos(1, 1)
+
term.clear() ------- clears the screen
 +
 
 +
term.setCursorPos(1, 1) ------- returns the cursor to the top of the screen

Revision as of 20:32, 28 April 2012


is what that string does

add = "add" ------ it says when i tell it to add then it codes it to the word add

subtract = "subtract" ------ the same as for add just with subtract

multiply = "multiply" ------ same as for add just with multiply

devide = "devide" ------ sameas for add just for devide

print ("Do you want to add, subtract, multiply or devide?") ------- prints the message written between (" and ")

write ("") ------- makes room for you to write if you want add, subtract, multiply or devide.

put = io.read() ------ reads what you write and codes it in to the word "put"

write ("Enter your first number: ") ------ makes room for you to write your first number.

input = io.read() ------ reads what you write above and codes it in to the word "input"

write ("Enter your second number: ") -------- makes room for you to write the second number.

output = io.read() ------- reads what you write above and codes it into the word "output"

if put == add ------ then checks if the word you wrote when you chose if you wanted to add, subtract, multiply or devide then it checks if its the same as add, if its not thn it does nothing

x = input + output ------- if the word you wrote was the same as add then this adds the first number (input) and the second number (output) and then codes it into the letter x

print ("That = ", x) ------- prints That = (and then what x is)

elseif put == subtract then ------- if its not add that you wrote then this checks if its subtract

x = input - output -------- if it was subtract then this subtracts the input from the output and codes it into the letter x

print ("That = ", x) ------- the same as for add

elseif put == multiply then ------- if its not add or subtract you wrote then it checks if its multiply

x = input * output ------- if it is it multiplies input and output and codes it into the letter x

print ("That = ", x)------ the same as for add

elseif put == devide then -------- if its not add, subtract or multiply you wrote then this checks if its devide

x = input / output ------- this devides input from output and codes them into the letter x

print ("That = ", x) ------- the same as for add

end ------ since we only got if then we only need 1 end

sleep(3) ------- waits 3 seconds before executing the next string

term.clear() ------- clears the screen

term.setCursorPos(1, 1) ------- returns the cursor to the top of the screen