This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Need Help building Calculator

Muzafar Ali
Ranch Hand
Posts: 34
Hello,
I am building a 4 functions calculator program, it is accepting a number then at next line an Arithmetic Operator then at another line another number then show calculation on only single operator.
i need help to modify it to accept data like this
12 + 12 - 2 * 2 = 20 as wel or
100 / 2 + 200 = 250 i mean it have to perform calculation from all four operators on single line or two or three

here is a program which is getting input like this
12
+
12
24
that i don't want.

i shall wait for you answers !
if you have an example code for this pupose send me i will study from that.

regards,
Muzafar

Eduardo Bueno
Ranch Hand
Posts: 155
Sorry but we are NotACodeMill. If you really did that code, you could easily do what you want just by looking at Scanner and String documentations.

Muzafar Ali
Ranch Hand
Posts: 34
Eduardo Bueno wrote:Sorry but we are NotACodeMill. If you really did that code, you could easily do what you want just by looking at Scanner and String documentations.

I know sir you are not a code mil,
i don't say that correct it as i say, i say that provide me sample which could work like that i shall study on that and after that i shall use that code in my program, you say that use Scanner and String documentation i will follow that now i shall study on those .

Thanks,
Muzafar

Campbell Ritchie
Sheriff
Posts: 48645
56
If you are planning to use precedences, you need to look at a tutorial about parsing, convert the infix expression to postfix, and calculate in postfix.

Kalabaw moo
Ranch Hand
Posts: 61
You could implement a stack data structure to your program for the operands and the operators including the "(" ")" parenthesis. It would be simpler to evaluate a postfix expression than to an infix expression.