Instead of that you need to be using Prefix or postfix notation. Try http://www.cs.man.ac.uk/~pjj/cs2121/fix.html as that will help you in converting any mathematical expression and evaluate that using the BODMAS Rule