title: Incorrect file output using arrays
body: <p>Hello everyone I am just learning my first programming language and have just corrected one error in my code only to be left with another error. Thankfully this is the last problem I need to solve but I'm having a little trouble doing it myself.</p>
  
  <p>The program is to read in a customer number and expenses associated with each customer number. It will then add a finance charge, output all expenses, total everything, and save each customers new balance to file along with their ID number in reverse order.</p>
  
  <p>beginningbalance.dat looks like </p>
  
  <pre><code>111
  200.00
  300.00
  50.00
  222
  300.00
  200.00
  100.00
  </code></pre>
  
  <p>and newbalances.dat SHOULD look like </p>
  
  <pre><code>222
  402.00
  111
  251.00
  </code></pre>
  
  <p>except depending on where in put the "count--" in the file writing loop, I end up with </p>
  
  <pre><code>222
  402.00
  111
  251.00
  -858993460
  -92559631349317830000000000000000000000000000000000000000000000.00
  </code></pre>
  
  <p>I can't figure out what I should do to get rid of these extra values. Any suggestions?</p>
  
  <p>Here is my code</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  
  
  int main()
  {
    int count = 0;
    const int size = 100;
    double customer_beg_balance, customer_purchases, customer_payments, finance_charge_cost, finance_charge = .01;
    int customer_number[size];
    double new_balance[size];
    double total_beg_balances=0,total_finance_charges=0,total_purchases=0,total_payments=0,total_end_balances=0;
  
  
    ifstream beginning_balance;
    beginning_balance.open("beginningbalance.dat");
  
    while(beginning_balance&gt;&gt;customer_number[count])
      {
          beginning_balance &gt;&gt; customer_beg_balance;
          beginning_balance &gt;&gt; customer_purchases;
          beginning_balance &gt;&gt; customer_payments;
  
          finance_charge_cost = customer_beg_balance * finance_charge;
  
          new_balance[count] = customer_beg_balance + finance_charge_cost + customer_purchases - customer_payments; 
          total_beg_balances+=customer_beg_balance;
          total_finance_charges+=finance_charge_cost;
          total_purchases+=customer_purchases;
          total_payments+=customer_payments;
          total_end_balances+=new_balance[count];
  
          cout&lt;&lt;fixed&lt;&lt;setprecision(2)&lt;&lt;setw(8)&lt;&lt;"Cust No  "&lt;&lt;"Beg. Bal.  "&lt;&lt;"Finance Charge  "&lt;&lt;"Purchases  "&lt;&lt;"Payments  "&lt;&lt;"Ending Bal.\n"
              &lt;&lt;customer_number[count]&lt;&lt;"        "&lt;&lt;customer_beg_balance&lt;&lt;"        "&lt;&lt;finance_charge_cost&lt;&lt;"       "&lt;&lt;customer_purchases&lt;&lt;"     "&lt;&lt;customer_payments&lt;&lt;"         "&lt;&lt;new_balance[count]&lt;&lt;endl;
  
  
          count++;                            
      }
  
    cout&lt;&lt;"\nTotals     "&lt;&lt;total_beg_balances&lt;&lt;"        "&lt;&lt;total_finance_charges&lt;&lt;"       "&lt;&lt;total_purchases&lt;&lt;"     "&lt;&lt;total_payments&lt;&lt;"         "&lt;&lt;total_end_balances&lt;&lt;endl;
  
    ofstream new_balance_file;
    new_balance_file.open("NewBalance.dat");
  
    while(count &gt;= 0)
    {
      count--;
      new_balance_file &lt;&lt;customer_number[count]&lt;&lt;endl;
      new_balance_file&lt;&lt; fixed&lt;&lt;setprecision(2)&lt;&lt;new_balance[count]&lt;&lt;endl;
  
    }
  
  
    new_balance_file.close();
  
  
  system("pause");
          return 0;
   }
  </code></pre>