//gathers and parses the users input and determines if it is "good" input public string PostFixInput(string userinput) { string e; // this will be our error message if ((userinput == null) || (userinput == "" || (userinput == " "))) // we will not tolerate nulls or empty inputs { e = "Null or the empty string are not valid postfix expressions."; Mystack.Clear(); return(e); } // Mystack.Clear(); string s;//determines action for the digits double a = 0.0; double b = 0.0; double c = 0.0; char[] deliChars = { ' ' }; ///parses based on spaces between the variables string[] vari = userinput.Split(deliChars); try //now is the first part of the string really a double, or are you just testing our program { a = Convert.ToDouble(vari[0]); Mystack.Push(a); } catch (FormatException) { e = "Improper input format. Stack became empty when expecting first operand."; Mystack.Pop(); return(e); } try// now is the second part of the string reallly a double, or you trying to trick us { b = Convert.ToDouble(vari[1]); Mystack.Push(b); } catch (FormatException) { e = "Improper input format. Stack became empty when expecting second operand."; Mystack.Pop(); return(e); } s = vari[2]; Mystack.Push(s); if (s.Length > 1) // checks to see if the last bit of the string is an operator, if you "accidently" put more chars this catches that { e = "Input Error " + s + " is not an allowed number or operator"; Mystack.Pop(); return(e); } else if (s.Equals("+") || s.Equals("-") || s.Equals("*") || s.Equals("/")) // allows the following { c = DoOperation(a, b, s); Mystack.Push(c); return(c.ToString()); } else // you must have not done the above else if statement to get here { e = "Improper operator: " + s + ", is not one of +, -, *, or /"; return(e); } }