|
|
|
|
|
|
|
#include <fstream.h> // For file I/O
void GetData( ifstream&, int&, float& );
void PrintData( int, int, float );
void PrintHeading();
int main()
{
int deptID1; // Department ID number for Store 1
int deptID2; // Department ID number for Store 2
float sales1; // Department sales for Store 1
float sales2; // Department sales for Store 2
ifstream store1; // Accounting file for Store 1
ifstream store2; // Accounting file for Store 2
storel.open(store1.dat);
store2.open(store2.dat);
if ( !store1 || !store2 ) // Make sure files
{ // were opened
cout << ** Can't open input file(s) ** < endl;
return l;
}
PrintHeading();
GetData(store1, deptID1, sales1); // Priming reads
GetData(store2, deptID2, sales2);
while (store1 && store2) // While not EOF
{
cout << endl;
if (deptID1 != deptID2) // Data validation test
cout << Data error: Department IDs don't match.
<< endl;
else
{
PrintData(deptID1, 1, sales1);
PrintData(deptID2, 2, sales2);
}
GetData(store1, deptID1, sales1);
GetData(store2, deptID2, sales2);
}
if ( !store1 && store2 ) // Data validation test
cout << Ran out of data for Store 1 before Store 2.
<< endl;
else if ( !store2 && store1 )
cout << Ran out of data for Store 2 before Store 1.
< endl;
|
|
|
|
|
|