title: RPN Calculator (issues with applying operands to the stack)
body: <p>I'm currently working on building on RPN calculator for a class that has to function through a stack of ints, and various functions. It also has to have input taken through cin statements and then sorted into integers or operands and either be pushed onto the stack or initiate the appropriate functions from the class to calculate. </p>
  
  <p>Most of it I have figured out and working, however I'm having a really weird problem that I can't figure out.</p>
  
  <p>It will take my first set of numbers and the first operand fine (for example, I enter 1 2 3 and the stack will show 3, 2, 1 as the contents) but after I apply a second operand I'm getting zeros thrown in before each answer. </p>
  
  <p>Example:  </p>
  
  <p>Input: 1 2 + 2 *</p>
  
  <p>Expected Output: 6</p>
  
  <p>What I Get: 0, 2, 0, 3 </p>
  
  <p>I'm not sure if this is an error in my push() function for the stack, or in main, or elsewhere. I haven't been able to find it. Any help would be appreciated, even just a point in the right direction!</p>
  
  <p>Here's the parts of the code I'm assuming are causing the problem somewhere:</p>
  
  <p>Main Function:</p>
  
  <pre><code>int main(){
  
    Stack mystack;
  
    std::string getIt; // taken as input
    int pushIt;  // converted to int and pushed if nessecary
  
    do{
      // get user input
      std::cin &gt;&gt; getIt;
      if(getIt == "@"){};
      if(getIt == "!") mystack.negate();
      if(getIt == "+") mystack.add();
      if(getIt == "-") mystack.subt();
      if(getIt == "/") mystack.div();
      if(getIt == "%") mystack.mod();
      if(getIt == "SUM") mystack.sumof();
      if(getIt == "R") mystack.reverse();
      if(getIt == "#") mystack.print();
      if(getIt == "$") mystack.clear();
      else {
        pushIt = atoi(getIt.c_str()); // I have no idea if this was
                                      //utilized correctly, feel free
       mystack.push(pushIt);          // to correct me here if not..
      }
     }
    while(getIt!="@"); // breaks on @
    return 0;
   }
  </code></pre>
  
  <p>Push, Pop, and Top Operators:</p>
  
  <pre><code>void Stack::push(const int&amp; val){
    Node* newNode = new Node;
    newNode-&gt;data = val;
    if(!head){
      head = newNode;
      return;
    }
    newNode-&gt;next = head;
    head = newNode;
  }
  
  
  void Stack::pop(){
    if(!head)
      return;
    if(head-&gt;next == NULL){
      delete head;
      head = NULL;
      return;
    }
    Node* deleteIt = head;
    head = head-&gt;next;
    delete deleteIt;
    return;
  }
  
  
  const int&amp; Stack::top() const throw(Oops) { //Oops returns
    if(head == NULL){                     // an error variable
      std::cout&lt;&lt;"ERROR!! : No values in the stack.";
    }      
    return head-&gt;data;
  }
  // I also don't know if I used the throw right here.. 
  </code></pre>
  
  <p>And, just incase I'm actually doing something wrong here instead... Here's one of my operation functions (+), the others are all coded similarly.</p>
  
  <pre><code>void Stack::add(){
    int num1 = top();
    pop();
    int num2 = top();
    pop();
    int sum = num2+num1;
    push(sum);
    return;
  }
  </code></pre>
  
  <p>Thanks!</p>