title: Using Stacks In C++ for infix and postfix expressions
body: <p>I'm writing a program that takes user input and uses stacks to convert an infix expression into a postfix expression based on precedence, with operands always going before operators. For example, if a user inputs:</p>
  
  <p>(a+b*c)</p>
  
  <p>then the program should display:</p>
  
  <p>abc*+</p>
  
  <p>so far, I have this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stack&gt;
  #include &lt;string&gt;
  
  
  using namespace std;
  
  int main()
  {
      stack&lt;char&gt; s;
      char input;
      while (cin.get(input) &amp;&amp; input != '\n')
          {
              if (isalnum(input))
                  cout &lt;&lt; input &lt;&lt; "\n";
              else if (input == '(')
                  s.push(input);
              else if (input == ')')
              {
          while (!s.empty() &amp;&amp; s.top() != '(')
              {
              cout &lt;&lt; s.top();
              s.pop();
          }
              if(!s.empty()) 
                      s.pop();
              else
                  cout &lt;&lt; "ERROR: No Matching ( \n";
          }
       else if (s.empty() &amp;&amp; input == '*'||'/'||'+'||'-' &amp;&amp; s.top() &lt; input) // Error Begins Here?
       {
           char a = '*';
           char b = '/';
           char c = '+';
           char d = '-';
           bool prec (char a, char b, char c, char d);
               return ('*' &gt; '/' &gt; '+' &gt; '-');
               s.push(input);
       }
           else if (input == '*'||'/'||'+'||'-' &amp;&amp; s.top() &gt;= input)
               while (!s.empty()) 
            {
                cout &lt;&lt; s.top();
            s.pop();
                    s.push(input);
            }
          }
      while (!s.empty())
      {
          cout &lt;&lt; s.top();
          s.pop();
      }
  }
  </code></pre>
  
  <p>Which compiles and runs but is not functioning as it should. When an expression like "ab" is input, the program will display "ab" as it should but if I input "a+b+c", then only "a" will be displayed. This means the program is not placing the operators into the stack to be displayed later on. What I need help with is modifying the program so that when an operator is input, it should be added onto the stack and then displayed based on it's precedence (*>/>+>-) after the operands, when the input is done.</p>
  
  <p>I'm quite new to C++ and programming in general, so any suggestions would be great.</p>