Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:03:27+00:00 2026-05-27T02:03:27+00:00

Hello everyone I am just learning my first programming language and have just corrected

  • 0

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.

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.

beginningbalance.dat looks like

111
200.00
300.00
50.00
222
300.00
200.00
100.00

and newbalances.dat SHOULD look like

222
402.00
111
251.00

except depending on where in put the “count–” in the file writing loop, I end up with

222
402.00
111
251.00
-858993460
-92559631349317830000000000000000000000000000000000000000000000.00

I can’t figure out what I should do to get rid of these extra values. Any suggestions?

Here is my code

#include <iostream>
#include <fstream>
#include <iomanip>
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>>customer_number[count])
    {
        beginning_balance >> customer_beg_balance;
        beginning_balance >> customer_purchases;
        beginning_balance >> 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<<fixed<<setprecision(2)<<setw(8)<<"Cust No  "<<"Beg. Bal.  "<<"Finance Charge  "<<"Purchases  "<<"Payments  "<<"Ending Bal.\n"
            <<customer_number[count]<<"        "<<customer_beg_balance<<"        "<<finance_charge_cost<<"       "<<customer_purchases<<"     "<<customer_payments<<"         "<<new_balance[count]<<endl;


        count++;                            
    }

  cout<<"\nTotals     "<<total_beg_balances<<"        "<<total_finance_charges<<"       "<<total_purchases<<"     "<<total_payments<<"         "<<total_end_balances<<endl;

  ofstream new_balance_file;
  new_balance_file.open("NewBalance.dat");

  while(count >= 0)
  {
    count--;
    new_balance_file <<customer_number[count]<<endl;
    new_balance_file<< fixed<<setprecision(2)<<new_balance[count]<<endl;

  }


  new_balance_file.close();


system("pause");
        return 0;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:03:28+00:00Added an answer on May 27, 2026 at 2:03 am

    Your condition is wrong

     while(count >= 0)
     {
        count--;
        new_balance_file <<customer_number[count]<<endl;
        new_balance_file<< fixed<<setprecision(2)<<new_balance[count]<<endl;
    
     }
    

    Should be count > 0 instead of count >= 0.

    This way count will iterate through values n, n-1, ... 1 and because you decrement it right at the beginning of the while statement, the values you’ll be operating with within your loop will be n-1, n-2.... 0, exactly what you need.

    By the way, if your course has already covered the for loop and you’re allowed to use it, then it’s more suitable, like this

    for(int i = count - 1; i >= 0; --i)
    {
        use i instead of count here.
    }
    

    Hope this helps and good luck with your studies!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello everyone I am newto programming and I am just a little bit confused.
Hello everyone I'm trying to make a jquery Menu just like the one in
Hello everyone I was just going trough http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html spring tutorial, and I thought its
Hello everyone I'm currently having 2 issues with the code below: Upon return of
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
First question here so hello everyone. The requirement I'm working on is a small
Hello everyone i currently have this: import feedparser d = feedparser.parse('http://store.steampowered.com/feeds/news.xml') for i in
Introduction : Hello Everyone, I have been looking for days for a way to
Hello everyone I have a question that I will describe as good as I
hello everyone I have 3 files: engine script #! /bin/tcsh -f cat $1 |./hello

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.