//2203 Lab #5 section 2
#include <iostream>
#include <fstream>
#include <string>
#include "Checkbook.h"

using namespace std;

int main()
{
  ifstream infile;
  string fname, account_action;
  float money;  // money amount from file
  Checkbook mycheckbook; 
  
  cout << "Enter your checkbook file name:  ";  
  cin >> fname;
  infile.open(fname.c_str());
  if(!infile) {
    cerr << "Error: Can't open file." << endl;
    return 1;
  } 
  
  infile >> account_action;   // read 1st item
  infile >> money;
  while(infile) 
  {
    if(account_action == "deposit")
      mycheckbook.Deposit(money);
    else if(account_action == "check" || account_action == "service")
      mycheckbook.WriteCheck(money);
    
    infile >> account_action; // read next item              
    infile >> money;
  }

  cout << endl << endl << "Account balance:  $" << mycheckbook.CurrentBalance() << endl;
  infile.close(); 
  return 0;
}

