title: Not getting right output when Overloading the '+' operator in Calculator Program for c++
body: <p>I can't seem to get the right output for #3. The output is supposed to be 12, but I get a junk. I don't really understand overloading, so can someone explain it to me, please? </p>
  
  <p>I tried different returns, and other things, but I can't seem to get it right. Would someone please explain?</p>
  
  <p>I'm not getting any errors, right now, just junk output.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Calculator
  {
  private:
  
  public:
  
      double total;
      double newNum;
  
      //default constructor
      Calculator()
      {
          total = 0;
      }
  
      double clear()
      {
          total = 0;
          return total;
      }
  
      void add(double num)
      {
          num += y;
      }
  
      void subtract(double num)
      {
          num -= y;
      }
  
      void multiply(double num)
      {
          total  *= num;
      }
  
      void divide (double num)
      {
          total /= num;
      }
  
      double display()
      {
          return total;
      }
  
      //parameterized constructor
      Calculator(double newNum)
      {
          x = newNum;
      }
  
      Calculator operator+(Calculator c)
      {
          return Calculator(y);
      }
  
  };
  
  int main() 
  {
      Calculator mycalc;
      mycalc.clear();
      mycalc.add(4.52);
      mycalc.add(3.789);
      mycalc.divide(2.6);
      mycalc.multiply(3.12);
      mycalc.subtract(2.678);
      cout &lt;&lt; mycalc.display() &lt;&lt; endl;       // prints out "7.2928"
      mycalc.clear();
      mycalc.add(5.0);
      cout &lt;&lt; mycalc.display() &lt;&lt; endl;       // prints out "5"
  
      //advanced stuff #1: add a constructor
      Calculator calc1;
      cout &lt;&lt; calc1.display() &lt;&lt; endl;  //prints out 0
  
      //advanced stuff #2: add a parameterized constructor
      Calculator calc2(5);
      cout &lt;&lt; calc2.display() &lt;&lt; endl; //prints out 5
  
      //advanced stuff #3: Define calculator addition (overload the '+' operator)
      Calculator calc3(7);
      calc1 = calc2 + calc3;
      cout &lt;&lt; calc1.display() &lt;&lt; endl;  //prints out 12
  
      //advanced stuff #4: Create an 'undo' method for the calculator
  //      mycalc.undo();
  //      mycalc.undo();
  //      cout &lt;&lt; mycalc.display()&lt;&lt; endl;  //prints out 7.2928
  
      return 0;
  }
  </code></pre>