# Infix Calculator

cehsu
4,015 views

### Open Source Your Knowledge, Become a Contributor

The goal today is to write a function that evaluates a string that contains an arithmetic expression. We will do this by writing an calc function that calculates the expression using a stack.

For example:

• calc("1 + 2 * (20 / 5 )") -> 9
• calc("1 + 2 - 3") -> 0
• calc("1 + 3 + ( ( 4 / 2 ) * ( 8 * 4 ) )") -> 68