title: infix to postfix expression converting code not working
body: <p>Following is my code in cpp to convert infix to postfix expression? I have tried everything but my code is not giving me the desired result?  Please somebody help me....plzzzzzz.</p>
  
  <p>It is just not working although I think that the code is right. I have spent a lot of time in checking this code and have checked the working of evry line but still it is not working.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;conio.h&gt;
  using namespace std;
  
  int k=-1,m=0;
  int j=0;
  string infi,postfi,operato;
  int precedence(char s)
  {
      switch(s)
      {
  
      case '+':
      case '-':     
      return 1;
      break;
      case '*':
      case '/':     
      return 2;
      break;
      case '$':
      return 3;
      break;
      case '(':
      return 4;
      break;
      case ')':
      return 5;
      break;
      }
  }
  void operat()
  {
       if(k==-1)
       {
  
                k++;
               operato[k]=infi[j];
               //cout&lt;&lt;operato[0]&lt;&lt;"mm";
       }
       else if(precedence(infi[j])==4)
       {
            //cout&lt;&lt;"0000";
            k++;
            operato[k]=infi[j];
       }
       else if(precedence(infi[j])==5)
       {
            //cout&lt;&lt;"0000";
            while(operato[k]!='(')
            {
                                   postfi[m]=operato[k];
                                   m++;
                                   k--;
            }
            k--;
       }   
       else if(precedence(infi[j])&gt;precedence(operato[k]))
       {
            //cout&lt;&lt;"0000";
            k++;
            operato[k]=infi[j];
       }
       else
       {
           //cout&lt;&lt;"0000";
           postfi[m]=operato[k];
           k--;
           m++;
           operat();
       }
    //cout&lt;&lt;postfi[0]&lt;&lt;"pp";   
  }
  
  int main()
  {
  
      cin&gt;&gt;infi;
  
      while(infi[j]!='\0')
      {
                           if(infi[j]=='+'||infi[j]=='-'||infi[j]=='*'||infi[j]=='/'||infi[j]=='('||infi[j]==')'||infi[j]=='$')
                           {
                                   operat();
                                   j++;
                           }
                           else
                           {
  
                               postfi[m]=infi[j];
                               //cout&lt;&lt;postfi[0];
                               //cout&lt;&lt;"me"&lt;&lt;m&lt;&lt;postfi[m];
                               m++;
                               j++;
                           }
      }
      while(k!=-1)
      {
                  postfi[m]=operato[k];
                  //cout&lt;&lt;postfi[0];
                  //cout&lt;&lt;"me"&lt;&lt;m;
                  //cout&lt;&lt;"meow"&lt;&lt;m&lt;&lt;postfi[m];
                  k--;
                  m++;
      }
      //cout&lt;&lt;postfi[0];
      int g;
      for(g=0;g&lt;m;g++)
       cout&lt;&lt;postfi[g];
      //getch();
      return(0);
  }
  </code></pre>