title: Linked List Calc only evaluates 1st number. c++
body: <p>I am working on a postfix calculator and I am very close to finishing but I am stumped on why my calculator is only evaluating the 1st input. For example, if I enter: "1 2 3 ++" it only pops the first number and displays "1" as the answer. I feel like this problem stems from the main loop where the numbers being entered and passed to the stack are not being pushed correctly. Any suggestions/tips are appreciated! Thanks! </p>
  
  <pre><code>class Dstack
  {
  
      public:
          Dstack();
          ~Dstack();
          void push(double value);
          bool pop(double &amp;value);
          int size();
          bool empty();
          int top();
  
      private:
  
          class Node
          {
              public:
                  Node(double value, Node *next)
                  {m_value = value; m_next = next;}
                  double m_value;
                  Node *m_next;
          };
          Node *m_head;
  
  
  };
  
  Dstack::Dstack()
  {
      m_head = NULL;
  }
  
  Dstack::~Dstack()
  {
      Node *ptr = m_head;
      while (ptr != NULL)
      {
          Node *temp;
  
          temp = ptr;
          ptr = ptr-&gt;m_next;
          delete temp;
      }
  }
  
  void Dstack::push(double value)
  {
      m_head = new Node(value, m_head);
  }
  
  bool Dstack::pop(double &amp;value)
  {
      //Node *ptr = m_head;
      if(m_head == NULL)
      {
          return false;
      }
      else
      {
              Node *temp = m_head;
              value = m_head-&gt;m_value;
              m_head = m_head-&gt;m_next;
              delete temp;
              return true;
      }
  }
  
  int Dstack::size()
  {
      int num_elements = 0;
  
      Node *ptr = m_head;
      while(ptr != NULL)
      {
          num_elements++;
          ptr = ptr-&gt;m_next;
      }
      return num_elements;
  }
  
  bool Dstack::empty()
  {
      if(m_head == NULL)
          return true;
  
      else
          return false;
  
  }
  
  //main
  
  void error()
  {
      cerr &lt;&lt; "Illegal" &lt;&lt; endl;
      exit(1);
  }
  
  
  int main()
  {
      double lVal, rVal, answer;
      Dstack stack;
      double num;
  
  
      while((cin.peek()) != -1)
      {
          if(cin.peek() &gt;= 'a' &amp;&amp; cin.peek() &lt;= 'z')
          {
              error();
          }
          if(isspace(cin.peek()))
          {
              cin.ignore();
              break;
          }
          if(isdigit(cin.peek()) || cin.peek() == '.')
             {
                 cin &gt;&gt; num;
                 if(cin.good())
                 {
                      stack.push(num);
                 }
             }
          else if(cin.peek() == '+')
          {
              rVal = stack.pop(num);
              lVal = stack.pop(num);
              answer = rVal + lVal;
              stack.push(answer);
              break;
          }
          else if(cin.peek() == '-')
          {
              rVal = stack.pop(num);
              lVal = stack.pop(num);
              answer = rVal - lVal;
              stack.push(answer);
              break;
          }
          else if(cin.peek() == '*')
          {
              rVal = stack.pop(num);
              lVal = stack.pop(num);
              answer = rVal * lVal;
              stack.push(answer);
              break;
          }
          else if(cin.peek() == '/')
          {
              rVal = stack.pop(num);
              lVal = stack.pop(num);
              answer = rVal / lVal;
              stack.push(answer);
              break;
          }
          else if(cin.peek() == '^')
          {
              rVal = stack.pop(num);
              lVal = stack.pop(num);
              answer = pow(rVal, lVal);
              stack.push(answer);
              break;
          }
          stack.pop(answer);
      }
  
      cout &lt;&lt; "\nAnswer: " &lt;&lt; answer &lt;&lt; endl;
      return 0;
  }
  </code></pre>