Reverse Polish Notation: Ignoring parentheses and spaces in input formula
<p>I am currently working with a reverse polish notation calculator. It is fully functional but I am running into issues with text input that will then be used to calculate the values. The program breaks if introduce a formula like <code>( 8 5 + ) 6 * =</code> . Is there a way to simply ignore any parentheses that show up in the input value? Also my program does split accordingly to space between each number but if I for get to add a space between operands or parentheses it also breaks: <code>(8 5 +)6 * =</code>.  If it is an invalid formulas <code>12 + =</code> ( missing a number) i would like to ignore them and just display in output textBox an error message.</p>

<p>Side Note: every formula is triggered by an ending <code>=</code>.</p>

<p><strong>Code</strong></p>

<pre><code>namespace rpncalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

      private string inputValue = "";

        private void RPNCalc(string rpnValue)
        {
            Stack&lt;int&gt; stackCreated = new Stack&lt;int&gt;();
            stackCreated.Clear();
            string[] inputArray = rpnValue.Split();
            int end = inputArray.Length - 1;
            int numInput;
            int i = 0;

            do
            {
                if ("=+-*/%^".IndexOf(inputArray[i]) == -1)
                {
                    try
                    {
                        numInput = Convert.ToInt32(inputArray[i]);
                        stackCreated.Push(numInput);
                    }
                    catch
                    {
                        MessageBox.Show("Please check the input");
                    }
                }

                    else if (inputArray[i]== "+")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push(store2 + store1);
                        }
                        catch
                        {
                        }
                    }

                    else if (inputArray[i]== "-")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push(store2 - store1);
                        }
                        catch
                        {
                        }
                    }

                    else if (inputArray[i]== "%")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push(store2 % store1);
                        }
                        catch
                        {
                        }
                    }

                    else if (inputArray[i]== "*")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push(store2 * store1);
                        }
                        catch
                        {
                        }
                    }

                    else if (inputArray[i]== "/")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push(store2 / store1);
                        }
                        catch
                        {
                        }
                    }

                    else if (inputArray[i] == "^")
                    {
                        try
                        {
                            int store1 = stackCreated.Pop();
                            int store2 = stackCreated.Pop();
                            stackCreated.Push((int)Math.Pow(store1, store2));

                        }
                        catch
                        {
                        }
                    }

            }
            while(i++ &lt; end &amp;&amp; inputArray[i]!= "=" &amp;&amp; stackCreated.Count != 0);
            string result = inputValue + " " + stackCreated.Pop().ToString() + Environment.NewLine;
            TxtOutputBox.AppendText(result);
            TxtInputBox.Clear();

        }

        private void TxtOutputBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void Btn_Calc_Click(object sender, EventArgs e)
        {
            inputValue = TxtInputBox.Text + " ";
            RPNCalc(inputValue);
        }
    }
}
</code></pre>

<p><img src="http://i.stack.imgur.com/8dwLe.jpg" alt="enter image description here"></p>
