title: Operator overload not working properly
body: <p>I am running into a problem with overloading an operator. </p>
  
  <p>The question that I am being asked to implement in my code:</p>
  
  <p>Eliminate the need for the “friend” access-right in the class by adding a proper accessor method (query) to the class and modifying the operator <code>+</code> to use the accessor instead of using the class attributes directly.
  Overload operator <code>+=</code> again as a helper so the following is possible:
  If <code>“d”</code> and <code>“e”</code> are double variables and <code>A</code> is an Account object. 
  <code>d = e += A</code>;
  The Balance or <code>A</code> should be added to the value of <code>“e”</code> and then the modified value returned</p>
  
  <p>my CPP file:</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;cstring&gt;
  #include "Account.h"
  using namespace std;
  
      Account::Account() {
              name_[0] = 0;
              balance_ = 0;
      }
      Account::Account(double balance) {
              name_[0] = 0;
              balance_ = balance;
      }
      Account::Account(const char name[], double balance) {
              strncpy(name_, name, 40);
              name_[40] = 0;
              balance_ = balance;
      }
  
  
      void Account::display(bool gotoNewline)const {
              cout &lt;&lt; (name_[0] ? name_ : "No Name") &lt;&lt; ": $" &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; balance_;
              if (gotoNewline) cout &lt;&lt; endl;
      }
  
      Account&amp; Account::operator+=(const Account&amp; other) {
  
              balance_ += other.balance_;
              return *this;
      }
  
      Account&amp; Account::operator=(const Account&amp; ls) {
  
              balance_ = ls.balance_;
              strncpy(name_, ls.name_, 40);
  
                      return *this;
  
      }
  
      Account operator+(const Account &amp;one, const Account &amp;two) {
              return Account(one.balance_ + two.balance_);
  
      }
      std::ostream&amp; operator&lt;&lt;(ostream&amp; os, const Account&amp; A) {
              A.display(false);
              return os;
      }
  
      Account&amp; Account::operator=(const char name[]) {
              strncpy(name_, name, 40);
  
              return *this;
      }
  
      double operator+=(double&amp; d, const Account&amp; a)
      {
              d += a;
              return d;
      }
  </code></pre>
  
  <p>My HEADER file:</p>
  
  <pre><code>#ifndef _ACCOUNT_H__
  #define _ACCOUNT_H__
  #include &lt;iostream&gt;
  
      class Account {
              char name_[41];
              double balance_;
      public:
              Account();
              Account(double balance);
              Account(const char name[], double balance = 0.0);
              void display(bool gotoNewline = true)const;
  
              Account&amp; operator+=(const Account&amp; other);
              Account&amp; operator=(const Account&amp; ls);
              Account&amp; operator=(const char name[]);
              friend Account operator+(const Account &amp;one, const Account &amp;two);
  
      };
  
      std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Account&amp; A);
      Account operator+(const Account &amp;one, const Account &amp;two);
      double operator+=(double&amp; d, const Account&amp; a);
  
  #endif
  </code></pre>
  
  <p>The MAIN.CPP:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Account.h"
  using namespace std;
  void displayABC(const Account&amp; A,
      const Account&amp; B,
      const Account&amp; C) {
      cout &lt;&lt; "A: " &lt;&lt; A &lt;&lt; endl &lt;&lt; "B: " &lt;&lt; B &lt;&lt; endl
              &lt;&lt; "C: " &lt;&lt; C &lt;&lt; endl &lt;&lt; "--------" &lt;&lt; endl;
  }
  int main() {
      Account A;
      Account B("Saving", 10000.99);
      Account C("Checking", 100.99);
      Account* AC[3] = { &amp;A, &amp;B, &amp;C };
      double balance = 0;
      displayABC(A, B, C);
      A = B + C;
      displayABC(A, B, C);
      A = "Joint";
      displayABC(A, B, C);
      A = B += C;
      displayABC(A, B, C);
      A = B += C += 100.01;
      displayABC(A, B, C);
      for (int i = 0; i &lt; 3; i++) {
              cout &lt;&lt; i + 1 &lt;&lt; "- " &lt;&lt; (balance += *AC[i]) &lt;&lt; endl;
      }
      cout &lt;&lt; "Total Balance: " &lt;&lt; balance &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>When i run it it seems to work properly for the first few outputs, but when it comes to the double operator it stops working. The output is supposed to be:</p>
  
  <pre><code>A: Saving: $10302.98
  B: Saving: $10302.98
  C: Checking: $201.00
  --------
  
  1- 10302.98
  2- 20605.96
  3- 20806.96
  Total Balance: 20806.96
  </code></pre>
  
  <p>but never reaches the <code>"1 - 2- 3- Total Balance:"</code> line. Any help is greatly appreciated. Thank you!</p>