Posted 24 October 2012 - 06:11 AM
Well, this is my first "Basic Calculator" program in CC. I am open to any comments on how I can make it better, and improve on my programing skills.
term.clear()
term.setCursorPos(1,1)
-- These lines are the two numbers the user inputs into the calculator.
io.write("Input first number.n")
first = io.read()
io.write("Input second number.n")
second = io.read()
-- These lines tell what problems the user can choose for those two numbers.
io.write("Would you like to add, subtract, multiply, or divide?n")
print("To add type: a")
print("To subtract type: s")
print("To multiply type: m")
print("To divide type: d")
type = io.read()
-- These lines print out the answer to the problem the user chose in the above lines.
if type=="a" then
io.write(first," plus ",second," equals: ",first + second,"n")
end
if type=="s" then
io.write(first," minus ",second," equals: ",first - second,"n")
end
if type=="m" then
io.write(first," times ",second," equals: ",first * second, "n")
end
if type=="d" then
io.write(first," divided by ",second," equals: ",first / second, "n")
end