By the sounds of it you just want an app that can give your the answers to general mathematical expressions. There's a lot of subtleties to consider here, while it may seem simple it isn't. A general purpose solution to this problem involves multiple complicated steps that humans do unconsciously:
- Turn a list of characters into a list of words (Scan)
- Turn a list of words into a tree representing the expression (Parse)
- Calculate each branch of the tree recursively until you get the result (Interpret)
For example:
1,2, ,+, ,4, ,*, ,2
12,+,4,*,2
(add 12 (multiply 4 2)) = (add 12 8) = 20
This area of programming is referred to as expression parsing, and while it's not the hardest thing it's quite theory heavy. I do remember somebody producing an expression parser using the eventsheet system awhile back, it was quite complicated...
There are 2 "cheats" solutions to this. The first is to have 2 text inputs for values, and a dropdown with a list of operators that a user can select. While it obviously doesn't match up to your examples it is very simple to implement. The second is to just evaluate each line of text as JavaScript, this is also super simple but allows your users to run arbitrary code. You could run a quick check over each letter and only evaluate it if it matches safe characters ( 0-9, +, -, /, * ).
For an intermediate solution you could create something that does the Scan, Parse and Interpret steps but uses a simpler format such as reverse polish(RP) notation 2 4 * 12 +
or S-expressions (add 12 (multiply 2 4))
. RP is the easiest as it is linear, not recursive, but is confusing for most people to write. S-expressions are easier to write but again aren't what people are used to writing. Both bypass the issue of operator precedence ( is 12 + 4 * 2
the same as (12 + 4) * 2
or 12 + (4 * 2)
) which is one of the more complicated issues around parsing.
For an advanced solution I would recommend reading up on Recursive Descent parsers or Pratt parsers.