This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help building Calculator

 
Muzafar Ali
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic