public void Solve(MathExpression expression) { if (expression.Validated) { if (expression.TryGetNumbers(out numbers)) { operands = new Queue <char>(expression.TransformToPolishNotation()); try { Compute(); } catch (Exception ex) { if (ex is System.ArithmeticException) { Console.WriteLine(ex.Message); } if (ex is System.DivideByZeroException) { Console.WriteLine("Divide by zero exception"); } } } } }
private static void Main(string[] args) { MathExpression expression = args.Length == 1 ? new MathExpression(args[0]) : new MathExpression(InputExpression()); PolishNotationCalc calc = new PolishNotationCalc(); calc.Solve(expression); }