Not sure what I'm missing.

Hi Everyone! So, my code pasted below shows that my program reads the balance and transactions from a file named checkIn.dat. I'm not sure if I correctly wrote the record structure that contains two members, code and amount.

• I'm also suppose to add a call, DisplayBal, after reading the beginning balance from the file so the beginning balance is displayed. (Not sure how to do this.)

•The last thing that I need is to display the following dollar totals at the end:
o Credits (additions to the account – deposits)
o Debits (deductions from the account – checks and ATM withdrawals)
o Service charges (ATM charges and negative balance charges)

Display the number of transactions in the file (this is a counter).
Use a structure definition for the totals. Update the total structure members in main. Display the totals in a function.

If anyone can help me out, I appreciate any help I can get! & if there is an excess of code, please do let me know.

Thanks so much~!

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std; 

// Function Prototypes
    void DisplayTitle();
    void DisplayBal(double);
    void DisplayDollarTotals(double, double, double);
    double GetBegBal(ifstream& inFile);
    double ProcessCheck(double, double);
    double ProcessDeposit(double, double);
    double ProcessATM(double, double);
    double ProcessSvcChg(double);
    
    // Global Constants    
    const double CHARGE = 10,
                 ATMFEE = 2;

struct checkRecord
{
    int transCode;
    double transAmount;
};

checkRecord Record(ifstream& inFile);

struct totals
{
    int credits;
    int debits;
    int service;
};

int main()
{
    // Variable Declarations
	using namespace std;
    ifstream inFile;
    double balance;

    inFile.open("C:\\checkIn.dat", ios::in);

    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);

    DisplayTitle();
    balance = GetBegBal(inFile);
    checkRecord record;
 
    while(! inFile.eof())
    {
        record = Record(inFile);
       
        switch(record.transCode)
        {
            case 1:
                balance = ProcessCheck(balance, record.transAmount);
                break;
            case 2:
                balance = ProcessDeposit(balance, record.transAmount);
                break;
            case 3:
                balance = ProcessATM(balance, record.transAmount);
                break;
        } 
		
		DisplayBal(balance);
		
		if(balance < 0)
			balance = ProcessSvcChg(balance);
        record.transCode = 0;
    }
    
    inFile.close();
    system ("pause");
}

checkRecord Record(ifstream& inFile)
{
	checkRecord rec;   
	inFile >> rec.transCode >> rec.transAmount;
	return rec; 
}

void DisplayTitle()
    {
        cout << "\n                      Check Register\n\n";
    }

double GetBegBal(ifstream& inFile)
{
    double x;
    inFile >> x;
    return x;
}

void DisplayBal(double balance)
{
    cout << "\t\tBalance = $" << setw(10) << balance;
}

void DisplayDollarTotals(double credit, double debit, double fee);
{
	int numberOfTrans = 0;
	inFile.get(numberOfTrans);

	if(numberOfTrans > 0);
	{
		numbeOfTrans = numberOfTrans + 1;
	}
	
	cout << "Number of transactions performed: " << number_of_transactions;
	cout << "Credit Total: ";
	cout << "Debit Total: ";
	cout << "Fee Total: ";
}

double ProcessCheck(double bal, double amt)
{
	cout << "\n  Check =    " << setw(10) << amt;
	return (bal - amt);
}

double ProcessDeposit(double bal, double amt)
{
	cout << "\n  Deposit =  " << setw(10) << amt;
	return (bal + amt);
}

double ProcessATM(double bal, double amt)
{
	cout << "\n  ATM     =  " << setw(10) << amt;
	bal = bal - amt;
	DisplayBal(bal);
	bal = bal - ATMFEE;
	cout << "\n  ATM Fee =  " << setw(10) << ATMFEE;
	return (bal);
}

double ProcessSvcChg(double bal)
{
	cout << "\n  Service chg =" << setw(8) << CHARGE;
	bal = bal - CHARGE;
	DisplayBal(bal);
	return (bal);
}
Last edited on
doesnt compile.
line 105, remove the semi-colon from the end of the line.
also you have this on line 108:
 
inFile.get(numberOfTrans);

but you don't pass in an 'inFile' so the compiler moans.

edit: oh.. you're not even using that method at all.

edit2:
1
2
3
// Global Constants    
const double CHARGE = 10,
	ATMFEE = 2;

these do not need to be global as they are only used in one method each, so move them to their respective methods.
Last edited on
Thank you, mutexe. This code should work now... Please let me know if it doesn't. I was also able to add the beginning balance onto the output screen. I just don't know how to go about totaling and displaying the number of transactions in the file. Any help I'd greatly appreciate. =)

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std; 

// Function Prototypes
	void DisplayTitle();
    void DisplayBal(double);
	void DisplayDollarTotals(double, double, double);
    double GetBegBal(ifstream& inFile);
	double ProcessCheck(double, double);
    double ProcessDeposit(double, double);
    double ProcessATM(double, double);
    double ProcessSvcChg(double);
	
struct checkRecord
{
    int transCode;
    double transAmount;
};

checkRecord Record(ifstream& inFile);

struct totals
{
	double credits;
	double debits;
    double service;
};

// Global Constants    
const double CHARGE = 10,
	          ATMFEE = 2;

int main()
{
    // Variable Declarations
	using namespace std;
    ifstream inFile;
    double balance;
	int transCount = 0;

	// Declare structures
	checkRecord record;

    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);

    DisplayTitle();
	balance = GetBegBal(inFile);

	inFile.open("C:\\Users\\quezon\\Desktop\\Project7CheckRegisterFINAL\\checkIn.dat",ios::in);
	if (inFile.fail( ))
	{
		cout << "Opening file failed.";
		system("pause");
		exit(1);
	}

    balance = static_cast <double> (GetBegBal(inFile));
	cout << setw(43) << "Balance = " << balance;

    while(! inFile.eof())
    {
        record = Record(inFile);
		transCount++;
       
        switch(record.transCode)
        {
            case 1:
                balance = ProcessCheck(balance, record.transAmount);
				break;
            case 2:
                balance = ProcessDeposit(balance, record.transAmount);
                break;
            case 3:
                balance = ProcessATM(balance, record.transAmount);
                break;
        }

		DisplayBal(balance);
		
		if(balance < 0)
		{
			balance = ProcessSvcChg(balance);
		}
	}

    inFile.close();
    system ("pause");
	return 0;
}

void DisplayTitle()
    {
        cout << "\n                      Check Register\n\n";
    }

double GetBegBal(ifstream& inFile)
{
    double x;
    inFile >> x;
    return x;
}

void DisplayBal(double balance)
{
    cout << "\t\t Balance = $" << balance;
}

checkRecord Record(ifstream& inFile)
{
	checkRecord rec;   
	inFile >> rec.transCode >> rec.transAmount;
	return rec; 
}

double ProcessCheck(double bal, double amt)
{
	cout << "\n  Check =    " << setw(10) << amt;
	return (bal - amt);
}

double ProcessDeposit(double bal, double amt)
{
	cout << "\n  Deposit =  " << setw(10) << amt;
	return (bal + amt);
}

double ProcessATM(double bal, double amt)
{
	cout << "\n  ATM     =  " << setw(10) << amt;
	bal = bal - amt;
	DisplayBal(bal);
	bal = bal - ATMFEE;
	cout << "\n  ATM Fee =  " << setw(10) << ATMFEE;
	return (bal);
}

double ProcessSvcChg(double bal)
{
	cout << "\n  Service chg =" << setw(8) << CHARGE;
	bal = bal - CHARGE;
	DisplayBal(bal);
	return (bal);
}
Last edited on
Topic archived. No new replies allowed.