Hi All,
I am trying to read data from two files and then compare them and only print the records on the screen that have a same ID.i.e TAGNO =CUSTOMERNO
For Eg
My Input Files are (a) Transaction (b) Customer detail
The data in file a is like:
TagNo Date Time Station
4092191 03/08/04 23:49:08 A
4749038 05/04/04 14:16:35 B
4092191 04/13/04 23:42:08 C
4092191 04/13/04 23:47:18 D
3873242 05/16/04 02:40:59 B
Data in File B
CustomerNo Initila Surname Street Suburb State Postcode
4092191 T Menon Evan Penrith NSW 2750
3873242 R Merritt Bent Mosman NSW 2090
Additional Criteria is , if the Grade is A the charges 2.20, B- 2.80, C-3.30 & D -3.80.
The expected output is :
Customer No:
Customer Name:
Address:
details of the transactions:
Customer No Date Time Grade Charges
Below is the code I am trying:
#include <stdlib.h>
#include <fstream.h>
#include <cstring.h>
#include <stdlib.h>
#include <iomanip.h>
void main()
{
string Dt,Tm;
float Charges;
string TagNumber, CustomerNo;
char Station;
string Intial,Surname,StreetNo,StreetName;
//char Intial[2],Surname[10],StreetNo[3],StreetName[20];
char StreetType[20],Surburban[20],State[20],Postcode[5];
float calc_charges( string Station );
//open the files
ifstream InStream\("a:\\trans.txt",ios::in\), InStream1\("a:\\customer.txt",ios::in\);
// check for Instream File, if the file doesn't exist, print error message
if \(InStream.fail\(\)\) // check for success
\{
cerr << "\\n Unable to open 'data.txt'!\\n";
exit \(-1\); //
\} // end if
if \(InStream1.fail\(\)\) // check for success
\{
cerr << "\\n Unable to open 'data.txt'!\\n";
exit \(-1\); //
\} // end if
while \(!InStream.eof\(\)\) // while not end-of-file:
\{
InStream >> TagNumber>>Dt>>Tm>>Station;
Charges = calc_charges\( Station \);
\} //while\(!input.eof\(\)\);
//open the customer detail file
// ifstream InStream1("a:\customer.txt",ios::in);
// if the file doesn't exist, print error message
if \(InStream1.fail\(\)\) // check for success
\{
cerr << "\\n Unable to open 'customer.txt'!\\n";
exit \(-1\); //
\} // end if
while \(!InStream1.eof\(\)\) // while not end-of-file:
\{
InStream1 >> CustomerNo>>Intial >> Surname>> StreetNo>> StreetName
>> StreetType >> Surburban>> State>> Postcode;
cout << "\\n Customer Name : " << Intial <<" " << Surname <<endl;
cout << " Address : " <<StreetNo << " "<<StreetName << " " <<StreetType<<endl;
cout << Surburban << " " << State << " " << Postcode <<endl;
cout << " Customer Number : " << CustomerNo <<endl;
cout <<endl;
cout << CustomerNo << "|" << Dt << "|" << Tm << "|" <<Station
<< " " << setw\(4\) << setiosflags\(ios::fixed\) << setprecision\(2\)
<< Charges << endl;
}
}
// function definition
float calc_charges( string Station )
{
float the_Charge;
if (Station == 'A')
the_Charge = 2.20;
else if (Station == 'B')
the_Charge = 2.80;
else if (Station == 'C')
the_Charge = 3.30;
else if (Station == 'D')
the_Charge = 3.80;
return the_Charge;
}
==================
The output that it gives is not correct.
Can someone Please help me out.
Thanks
rooh