# PEMDAS Calculator

• November 10th, 2013, 08:22 PM
aesguitar
PEMDAS Calculator
I'm writing a calculator, and to start, I'm writing basic arithmetic functionality. I've figured out how to tackle the "EMDAS" portion of the Order of Ops, however, I don't have a clue on how to simplify parentheses. The code I've written doesn't work in that regard, though everything else so far works great. How would you guys do the parentheses?

Code :

```pseudo-code which needs revising/reworking (I've written actual code, but it's fairly confusing...)   solveParentheses(String[] equation):   loop until no more parentheses:   find first parenthesis store its location in a variable   find close parenthesis store its location in a variable   If found one but not the other, give error message   save the content of the parentheses into an array   that array = solveParentheses(that array)   simplify order of ops inside parentheses   set the location of end parenthesis to result of simplification   set indices between the first parenthesis and result to "null"   :end loop   count number of null values   new array of length equation.length-nullcounter   fill array with non-null values   return array   :end function```
• November 10th, 2013, 09:17 PM
Junky
Re: PEMDAS Calculator
7 + 3 infix
7 3 + postfix

The easiest way to evaluate infix equations is to convert them to post fix first.
• November 10th, 2013, 10:09 PM
aesguitar
Re: PEMDAS Calculator
That's not how my algorithm works... Care to elaborate?
• November 10th, 2013, 10:24 PM
Junky
Re: PEMDAS Calculator
Maybe its not how YOUR algorithm works but I suggested a different algorithm you can use. Have you bothered to Google "infix to postfix"?
• November 10th, 2013, 10:53 PM
aesguitar
Re: PEMDAS Calculator
Yes, I still don't know what it does.