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

Simple Maths calculator

Started by kobkob1, 26 June 2015 - 05:46 PM
kobkob1 #1
Posted 26 June 2015 - 07:46 PM
This is just a simple calculator I wrote. Tell me if it works ok for you, and if you find anything wrong with it please tell me!
This just includes addition, subtraction, multiplication and division.
pastebin code: pastebin get 3xb5hiGh calculator
This is my first code, and works on anything, pocket computer, computer or monitor
Updated Maths, with in built monitor functionality: pastebin get Qd5Ex2hE calculator.
Edited on 28 June 2015 - 06:13 PM
Creator #2
Posted 26 June 2015 - 09:57 PM
Well, I noticed several thing:
  • You have to tonumber the numbers the user inputs (Did you even test the calculator, should have errored right away!)
  • You'd actually want:
    
    pastebin get 3xb5hiGh calculator
    
  • What happens when you input a complex equation, such as:
    
    5+3/7^4
    
Edited on 26 June 2015 - 07:58 PM
kobkob1 #3
Posted 26 June 2015 - 10:59 PM
Well, I noticed several thing:
  • You have to tonumber the numbers the user inputs (Did you even test the calculator, should have errored right away!)
  • You'd actually want:
    
    pastebin get 3xb5hiGh calculator
    
  • What happens when you input a complex equation, such as:
    
    5+3/7^4
    
I did test it, it worked fine for me. As for the complex equation, it is a simple calculator. It only works with simple equations. And before you go are you sure that it works with only simple equations, yes I am. I tried brackets with it and it came up with an arthmic error.
And for the pastebin code, you can put any name in for it. I called mine maths.
EDIT: By simple equation I mean x +,-,/,* y. In the code you see print( x func y ). I will try to expand it when I can, but keep in mind this is my first piece of fully functional code.
Edited on 26 June 2015 - 09:03 PM
Bomb Bloke #4
Posted 27 June 2015 - 01:38 AM
(Did you even test the calculator, should have errored right away!)

Did you?

;)/>
flaghacker #5
Posted 28 June 2015 - 11:49 AM
(Did you even test the calculator, should have errored right away!)

Did you?

;)/>/>

From the lua manual about arithmetic operators:
If the operands are numbers, or strings that can be converted to numbers (see §2.2.1), then all operations have the usual meaning.

Basically,
"10"/"2" == 5

Quite a unique but confusing feature, as comparing numbers and strings doesn't work.
kobkob1 #6
Posted 28 June 2015 - 08:34 PM
New calculator program:
pastebin get HgDJ5zJY calculator
biggest yikes #7
Posted 07 July 2015 - 03:57 PM
Edit your main post instead of putting updates in replies
Lupus590 #8
Posted 07 July 2015 - 10:35 PM
Edit your main post instead of putting updates in replies

Updates don't bump the thread, and by posting a reply you can track changes. Updates are also one of the only types bump that is allowed on the forums.
Personally I do both, update the OP and add a reply with only the change (usually doing a part quote of my self)
Edited on 07 July 2015 - 08:37 PM
Lyqyd #9
Posted 08 July 2015 - 12:45 AM
Adding a reply is fine as long as it's substantive. If you just post "bump", or similar things, the post is likely to be deleted just like other entirely useless posts.
biggest yikes #10
Posted 09 July 2015 - 01:50 PM
Putting a reply is fine, but it's probably smart to update the original post with any information or new pastes aswell.
kobkob1 #11
Posted 10 July 2015 - 11:12 PM
^ To all the above: First off, I had no intention of bumping the thread. This is not the best piece of code, and besides, bumping it doesnt get me any brownie points.
Second: I will update the main post now along with reply posts. Thank you for reminding me
Waitdev_ #12
Posted 19 July 2015 - 12:34 PM
pastebin code: pastebin get 3xb5hiGh calculator
yeah, i love pastebin codes.