I have a program where it reads 2 files, one of them containing a file with customer number (int), customer name (string) and balance (double).
There are 7 lines, but my program would only read the first line 7 times. This program is confusing me as to why they won't update.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
int Mcust_num; //master customer number
string Mcust_name; //master customer name
string Mlast_name;
double Mcust_bal; //master customer balance
string line;
char Tcode; //transaction code type
int Tcust_num; //transaction customer number
string Titem_name; //transaction item name
int Tquant; //transaction quantity order
double Tcostpay; //transaction cost/payment
fstream masterfile ("masterfile.txt");
fstream transactionfile ("transactionfile.txt");
masterfile >> Mcust_num >> Mcust_name >> Mlast_name >> Mcust_bal; //read master file
transactionfile >> Tcode >> Tcust_num >> Titem_name >> Tquant >> Tcostpay; //read transaction file
if ( (masterfile.is_open()) && (transactionfile.is_open()) ) //if both masterfile and transaction file are open
{
while ( (!masterfile.eof()) && (!transactionfile.eof()) ) //while neither are not end of file
{
getline (masterfile, line);
// cout << line << endl;
if (Mcust_num == Tcust_num) //if transaction and master customer numbers equal to each other
{
if (Tcode == 'O')
{
Mcust_bal = Mcust_bal + (Tcostpay * Tquant);
}
else
{
Mcust_bal = Mcust_bal - Tcostpay;
}
cout << '\t' << Tcode << '\t' << Tcust_num << '\t' << Titem_name << '\t' << Tquant << '\t' << Tcostpay << endl;
} //closes transaction and master cust numbers equals if
// cout << '\t' << line << endl;
cout << '\t' << Mcust_num << '\t' << Mcust_name << " " << Mlast_name << endl;
cout << '\t' << "Previous Balance: $" << Mcust_bal << endl;
// cout << '\t' << Tcode << '\t' << Tcust_num << '\t' << Titem_name << '\t' << Tquant << '\t' << Tcostpay << endl;
cout << '\t' << '\t' << "Balance Due: " << '\t' << "$" << Mcust_bal << endl;
cout << endl;
} //closes while statement
masterfile.close();
transactionfile.close();
} //closes if statement
else cout << "Unable to open file";
system("PAUSE");
return 0;
}