Hey everyone, I need a little help understanding some of the logic or code behind a project I have to do. I need to read a checkbook register file one line at a time, and calculate the balance by adding deposits and subtracting checks.
I've prompted the user to enter the file, but I need to ignore whitespace so if they put a space, it doesn't cause a mess. I thought that skipws would do that, but I might not be using it right.
Another catch is that I must remove/ignore the colons from the input lines separating each line into four separate pieces of data: the word "deposit," a date, the recipient of the check (or a dash), and the amount of the check or deposit.
Here's what the input would like like as a test case:
deposit:July 7:-:300
416:July 8:Albertsons:15.85
417:7/9:Checker Auto:19.95
Lines that begin with "deposit" represent deposits; the fourth field represents the deposit amount and is added to the balance. The third field of a deposit only contains a dash. ones that begin with a number represent checks; the fourth field represents the check amount and is subtracted form the balance.
The hard part im understanding is the skipws for the whitespace, and the adding/subtracting lines. Here's my code thus far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
string FileName;
void starline();
int main()
{
cout << "Enter a file name (including extension): " << endl;
cin >> skipws >> FileName;
ifstream input(FileName);
if (!input.good())
{
cerr << "Unable to open file" << endl;
exit(1);
}
while (!input.eof())
{
starline();
char deposit[15];
input.getline(deposit, 15, ':');
cout << left << setw(15) << deposit;
char date[15];
input.getline(date, 15, ':');
cout << setw(15) << date;
char place[15];
input.getline(place, 15, ':');
cout << setw(15) << place;
char money[15];
input.getline(money,15);
cout << right << setw(15) << "$ " << money << right << endl;
starline();
}
return 0;
}
void starline()
{
for(int j=0; j<65; j++)
cout << '-';
cout << endl;
}
|
It runs fine, there aren't any errors, just need help understanding what is being asked.