title: How to calculate the factorial of n using stacks
body: <p>I need to calculate the factorial of n using stacks and the code I made doesn't return any results. I also don't know what pop stack really does ( What it's second parameter is for ) so I just used a random value there. I used <code>int **x;</code> because I didn't know what to put here <code>pop(&amp;mystack,*x);</code>.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int n;
  int aux;
  int aux1;
  int aux2;
  int **x;
  typedef struct {
      int content[100];
      int top;
  } stack;
  stack mystack;
  
  int push(stack *somestack,int somevalue)
  {
      if (somestack-&gt;top+1&gt;=100)
          return 1;
      (*somestack).top++;
      (*somestack).content[(*somestack).top]=somevalue;
      return 0;
  }
  
  int pop(stack *somestack, int *oldvalue)
  {
      if((*somestack).top==0)
      {
          return 1;
      }
      *oldvalue=(*somestack).content[(*somestack).top];
      return 0;
  }
  
  int main()
  {
      cout&lt;&lt;"n=";
      cin&gt;&gt;n;
      push(&amp;mystack,n);
      int direction=1;
      while(mystack.top&gt;=1)
      {
          if((direction==1)&amp;&amp;(mystack.content[mystack.top]&gt;1))
          {
              aux=mystack.content[mystack.top];
              push(&amp;mystack,aux-1);
          }
          else
          {
              if(mystack.content[mystack.top]==1)
              {
                  direction=0;
              }
              else
              {
                  if(aux1&lt;n)
                  {
                      aux1=mystack.content[mystack.top];
                      aux2=aux1*(aux1+1);
                      pop(&amp;mystack,*x);
                      mystack.content[mystack.top]=aux2;
                  }
              }
          }
      }
      cout&lt;&lt;endl&lt;&lt;mystack.content[0];
      return 0;
  }
  </code></pre>