Difference between revisions of "Calculator Tutorial"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page with "add = "add" subtract = "subtract" multiply = "multiply" devide = "devide" print ("Do you want to add, subtract, multiply or devide?") write ("") put = io.read() write ("Enter ...")
 
Line 1: Line 1:
 
add = "add"
 
add = "add"
 +
 
subtract = "subtract"
 
subtract = "subtract"
 +
 
multiply = "multiply"
 
multiply = "multiply"
 +
 
devide = "devide"
 
devide = "devide"
 +
 
print ("Do you want to add, subtract, multiply or devide?")
 
print ("Do you want to add, subtract, multiply or devide?")
 +
 
write ("")
 
write ("")
 +
 
put = io.read()
 
put = io.read()
 +
 
write ("Enter your first number: ")
 
write ("Enter your first number: ")
 +
 
input = io.read()
 
input = io.read()
 +
 
write ("Enter your second number: ")
 
write ("Enter your second number: ")
 +
 
output = io.read()
 
output = io.read()
 +
 
if put == add then
 
if put == add then
 +
 
x = input + output
 
x = input + output
 +
 
print ("That = ", x)
 
print ("That = ", x)
 +
 
elseif put == subtract then
 
elseif put == subtract then
 +
 
x = input - output
 
x = input - output
 +
 
print ("That = ", x)
 
print ("That = ", x)
 +
 
elseif put == multiply then
 
elseif put == multiply then
 +
 
x = input * output
 
x = input * output
 +
 
print ("That = ", x)
 
print ("That = ", x)
 +
 
elseif put == devide then
 
elseif put == devide then
 +
 
x = input / output
 
x = input / output
 +
 
print ("That = ", x)
 
print ("That = ", x)
 +
 
end
 
end
 +
 
sleep(2)
 
sleep(2)
 +
 
term.clear()
 
term.clear()
 +
 
term.setCursorPos(1, 1)
 
term.setCursorPos(1, 1)

Revision as of 20:17, 28 April 2012

add = "add"

subtract = "subtract"

multiply = "multiply"

devide = "devide"

print ("Do you want to add, subtract, multiply or devide?")

write ("")

put = io.read()

write ("Enter your first number: ")

input = io.read()

write ("Enter your second number: ")

output = io.read()

if put == add then

x = input + output

print ("That = ", x)

elseif put == subtract then

x = input - output

print ("That = ", x)

elseif put == multiply then

x = input * output

print ("That = ", x)

elseif put == devide then

x = input / output

print ("That = ", x)

end

sleep(2)

term.clear()

term.setCursorPos(1, 1)