Please help with file processing problem

I have to have three files
a. Masterfile - contains customer name, Acct number and balance
b. Transaction file -processes monetary transactions made by a client
c. PrintInvoice file - this file takes the transactions made by a single client and output them under the clients name and Acct Number

I have processed file the Masterfile and the Transaction file however I am having problems with the Print invoice file. Apparently when I run the program it just output data from the transaction file for the first client in the master file. My code for the Print Invoice file is below

#include
#include


int main ()
{

int t_account_no, m_account_no, t_TransacCode;
char t_PayType, m_FName[30], m_LName[30], t_ItemOrder[30];
double t_amount, m_balance, new_balance=0.00;


fstream master("a:master.txt", ios::in);//opens master file for reading
fstream transac("a:Transac.txt", ios::in);//opens transaction file for reading

while (!transac.eof()) {

while(master>>m_account_no>>m_FName>>m_LName>>m_balance)
{ cout<<m_account_no<<' '<<m_FName<<' '
<<m_LName<<' '<<m_balance<<endl; while transac>>t_account_no>>t_PayType>>t_TransacCode
>>t_ItemOrder>>t_amount)
{
if(m_account_no == t_account_no)
{
cout<<t_PayType<<' '<<t_TransacCode<<' '
<<t_ItemOrder<<' '<<t_amount<<endl;
}
}
cout<<endl;
}
}



return 0;
}

Comments

  • [blue]Beware of trying to access a floppy disk drive for file i/o because they are notorious for failing at the most inopportune time.[code]while(file_1 has data to read)
    {
    ...

    while(file_2 has data to read)
    {
    ...
    }

    file_2.clear();
    file_2.seekg(0L, ios::beg);
    }[/code]Give that a try.[/blue]

    : I have to have three files
    : a. Masterfile - contains customer name, Acct number and balance
    : b. Transaction file -processes monetary transactions made by a client
    : c. PrintInvoice file - this file takes the transactions made by a single client and output them under the clients name and Acct Number
    :
    : I have processed file the Masterfile and the Transaction file however I am having problems with the Print invoice file. Apparently when I run the program it just output data from the transaction file for the first client in the master file. My code for the Print Invoice file is below
    :
    : #include
    : #include
    :
    :
    : int main ()
    : {
    :
    : int t_account_no, m_account_no, t_TransacCode;
    : char t_PayType, m_FName[30], m_LName[30], t_ItemOrder[30];
    : double t_amount, m_balance, new_balance=0.00;
    :
    :
    : fstream master("a:master.txt", ios::in);//opens master file for reading
    : fstream transac("a:Transac.txt", ios::in);//opens transaction file for reading
    :
    : while (!transac.eof()) {
    :
    : while(master>>m_account_no>>m_FName>>m_LName>>m_balance)
    : { cout<<m_account_no<<' '<<m_FName<<' '
    : <<m_LName<<' '<<m_balance<<endl; while transac>>t_account_no>>t_PayType>>t_TransacCode
    : >>t_ItemOrder>>t_amount)
    : {
    : if(m_account_no == t_account_no)
    : {
    : cout<<t_PayType<<' '<<t_TransacCode<<' '
    : <<t_ItemOrder<<' '<<t_amount<<endl;
    : }
    : }
    : cout<<endl;
    : }
    : }
    :
    :
    :
    : return 0;
    : }
    :
  • Thank you very much. I tried the code that you gave me.
    It works however when I run the code the window with the exe. stick and I have to shut Borland down.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories