开发者

What's the easiest approach for a calculator keypad algorithm?

Want to code a key pad for an calculator. What I want to make is:

Keypad with keys from 0 to 9 Special keys: + -开发者_如何学Python * / . =

My conceptual so far:

When a numeric key is pressed, convert it's int value into an string and append that string to the bufferString. That way the input value gets built up. When the user presses . (to make a float value), check if . is already in the bufferString. If it is, ignore that.

But: is that really a good way to go? Or should I do all this number input stuff pure mathematically?


The idea is to convert a infix expression to a postfix expression (Reverse Polish notation) using the the Shunting yard algorithm. Then the postfix expression is easy to resolve.


Why converting from int to string when you could just pass directly a string? Everything else looks ok for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜