how can i make a program by using like this(25/6+3-83/2)to get the sum of them?

Recommended Answers

All 4 Replies

Do you mean you need a program that can accept inputs in the style of your example and correctly determine the value?
I would separate the string on the mathmatical operators (+,-,x, /) and bracket, then use the BODMAS rule to figure out the order for which the operations take place.
But your question is unclear. Am I on the right track?

It is a matter of operator precidence. Multiplication and division are of equal precidence, as are addition and subtraction. Multiplication and division have higher precidence than addition or subtraction. Therefore, you must put the desired expressions inside parentheses. IE: (2*5/6+3-8*3/2) would be likely equivalent to ((2*5)/6)+3-((8*3)/2). Is this your intention? Other possibilities could be (2*(5/6))+((3-8)*(3/2)). There are other permutations that could be applied, and in most cases the results are very different.

This is mostly done with what is called a recursive descent parser

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.