Я только начал учиться программировать несколько месяцев назад, и это мой первый язык программирования.Я написал эту программу, чтобы получить номер клиента из «BeginningBalance.dat» вместе с покупками и платежами клиентов.
После прочтения сборов для каждого клиента он добавит финансовый сбор и все подсчитает, затем запишет новые конечные балансы для каждого номера клиента в обратном порядке.
Итак, начальные данные.dat выглядит как
111
200.00
300.00
50.00
222
300.00
200.00
100.00
, а NewBalance.dat должен выглядеть как
222
402.00
111
251.00
Теперь все, что читается в NewBalance.dat: -858993460-9.25596e + 061333655222402111251-858993460
Вот мой код, если кто-нибудь может помочь.
#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(new_balance_file << customer_number[count] && count >= 0)
{
new_balance_file << new_balance[count];
count--;
}
new_balance_file.close();
system("pause");
return 0;
}