This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Noobly's profile picture

My First Basic Calculator

Started by Noobly, 24 October 2012 - 04:11 AM
Noobly #1
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
ficolas #2
Posted 24 October 2012 - 09:33 PM
Dont upload txt files ^_^/>/>
Pastebin is better
Noobly #3
Posted 24 October 2012 - 10:55 PM
Dont upload txt files ^_^/>/>
Pastebin is better
I'm sorry about that. It should be fixed now. This was my first post as you could see, so I wasn't so sure about all the tools on this site.
GeniusName3 #4
Posted 02 November 2012 - 12:43 PM
I am having a problem,it doesn't print out the output.I entered 2 numbers then used m (doesn't appear to work for me for the other ones either) and it just showed the first number that I entered.I have a suggestion too:maybe make it where you can multiply more than 2 numbers?That would be awesome :D/>/>
Skullblade #5
Posted 02 November 2012 - 12:59 PM
Nice program. Basic but it does everything it needs to. One suggestion is to give it "click support" were you can click on the numbers and operators like an actual calculator.
Personal preference - use + - * / instead of a s m d: Just a preference you don't have to change it
casr144 #6
Posted 03 November 2012 - 06:24 AM
I agree with skullblade. You should have an area at the left-hand side that has a numpad with 0-9 and +-*/ on it, so that you can just click on numbers and operators.