Ok, I have been trying to work this thing for a week. It is a program that is supposed to read from 2 files (.dat) and write to a third file (.dat) then update one of the first files.
i.e.
read oldmast.dat
read trans.dat
compare data
write data and changes to newmast.dat
update oldmast.dat to match info in newmast.dat
I know how to make it read the entire files, but I don't know how to make it pull only what I need to compare. I'm not looking for handouts, just a little help(don't want confusion on this).
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
string line;
int accountNumber;
string firstName;
string lastName;
double currentBalance;
double dollarAmount;
ifstream inOldMaster("oldmast.dat", ios::in);
ifstream inTransaction("trans.dat", ios::in);
ofstream outNewMaster("newmast.dat", ios::in);
//oldmast.dat
if(!inOldMaster)
{
cerr << "File could not be opened." << endl;
exit(1);
}
cout << "Contents of oldmast.dat \n\n";
cout << left << setw(10) << "Account" << setw(13) << "First Name" << setw(13) << "Last Name" << setw(13) << "Balance" << endl << fixed << showpoint;
while(inOldMaster >> accountNumber >> firstName >> lastName >> currentBalance)
{
cout << left << setw(10) << accountNumber << setw(13) << firstName << setw(7) << lastName << setw(13) << setprecision(2) << right << currentBalance << endl;
}
inOldMaster.close();
cout << "\n\n\n\n";
//trans.dat
if(!inTransaction)
{
cerr << "File could not be opened." << endl;
exit(1);
}
cout << "Contents of trans.dat \n\n";
cout << "Account" << setw(15) << right << "Dollar Amount" << endl;
while(inTransaction >> accountNumber >> dollarAmount)
{
cout << accountNumber << setw(13) << setprecision(2) << right << dollarAmount << endl;
}
cout << "\n\n\n";
return 0;
}
contents of oldmast.dat
accountNumber firstName lastName currentBalance
100 john doe 234.43
200 sally sue 124.52
......
contents of trans.dat
accountNumber dollarAmount
100 100.00
200 -25.99
......
It is supposed to match the account numbers and add the dollar amount to the current balance to create a new current balance.
It is also supposed to print out a statement for account numbers that do not have a match, BUT I will try to get that myself first. I'm just trying to get it to do the other part of matching and adding. Thanks in advance for the help.