Banking Program

Trying to design a banking program. So, the program starts by having the user enter his/her initial amount in the bank. Then, a menu displays asking if the user wants to make a deposit, withdrawal by check, or withdrawal by ATM. There is also a selection of fees, which displays the bank fees and the fees accrued based on the transaction. Right now, the program does everything I want it to do, except upon exit. Upon exit, or in my code, the decision not to make another transaction, I'd like my program to display a list of all the transactions made. I've not learned about lists yet, so my idea was to store each of the transactions into an array, yet I am struggling to do so. In terms of my code, I'd like the displaySummary() method to do this. As it's set right now, it is not what I'm looking for, so ignore the code. Any help would be greatly appreciated. Here is my code so 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

#include <iostream>
#include <iomanip>
using namespace std;



class CheckingAccount
{
    
public:
    
	CheckingAccount() { runningBalance = 0; depositcount = 0; checkcounttot = 0; checkcount = 0; atmcounttot = 0; atmcount = 0; totalcount = 0; depositfees = 0;checkfees = 0; atmfees = 0; totalfees = 0; }
    
	void putInitialBalance(double w) { runningBalance = w; }
	void calcDep(double);
	void calcCheck(double);
	void calcATM(double);
    void displayFees();
	void displayBalance();
    void displaySummary();
    
    
private:
    
	double runningBalance;
    int depositcount, checkcounttot, checkcount, atmcounttot, atmcount, totalcount;
    double depositfees, checkfees, atmfees, totalfees;
   // double depositarr[1000], checkarr[1000], atmarr[1000];
    
};


void CheckingAccount::calcDep(double amount)
{
	runningBalance += amount - 0.25;
    ++depositcount;
    ++totalcount;
    
    /* for (int i = 0; i < depositcount; i++)
        amount = depositarr[i];
    
    cout << depositarr; */
}

void CheckingAccount::calcCheck(double amount)
{
	if (runningBalance - amount >= 0)
	{
		runningBalance -= amount;
        ++checkcounttot;
	}
    
	else if (runningBalance - amount < 0)
	{
		runningBalance -= (amount + 35.00);
        ++checkcount;
        ++checkcounttot;
        ++totalcount;
	}
}

void CheckingAccount::calcATM(double amount)
{
	char answer;
    
	if (runningBalance - amount >= 0)
	{
        runningBalance -= amount;
        ++atmcounttot;
	}
    
    else if (runningBalance - amount < 0)
    {
        cout << "\nWithdrawing " << amount << " will overdraft your account and accrue a $35.00 overdraft fee." << endl;
		cout << "Do you wish to continue with this transaction? [Y/N]? ";
		cin >> answer;
        
		if (answer == 'Y' || answer == 'y')
		{
			runningBalance -= (amount + 35.00);
            ++atmcount;
            ++atmcounttot;
            ++totalcount;
		}
		else if (answer == 'N' || answer == 'n')
		{
			cin.clear();
		}
    }
}

void CheckingAccount::displayFees()
{
    depositfees += (double(depositcount)*0.25);
    checkfees += (double(checkcount)*35.00);
    atmfees += (double(atmcount)*35.00);
    
    
    cout << endl  << endl << "Bank fees include: " << endl;
    cout << "$0.25 Deposit fee." << endl;
    cout << "$35.00 Overdraft fee for bounced check." << endl;
    cout << "$35.00 Overdraft fee for exceeding available amount via ATM withdrawal." << endl << endl;
    
    cout << "So far, you've made " << depositcount << " deposits, accruing a deposit bank fee of $" << depositfees << "." << endl;
    cout << "You've made " << checkcount << " check withdrawals in which the check bounced, accruing an overdraft fee of $" << checkfees << "." << endl;
    cout << "You've made " << atmcount << " ATM withdrawals, despite insufficient funds, accruing an overdraft fee of $" << atmfees << "." << endl << endl;
    
    totalfees += depositfees + checkfees + atmfees;
    cout << "In total, you've made " << totalcount << " transactions, amounting in $" << totalfees << " in banking fees." << endl << endl;
    
}

void CheckingAccount::displayBalance()
{
	cout << "Total Balance: " << setprecision(2) << fixed << runningBalance << endl << endl;
}

void CheckingAccount::displaySummary()
{
    cout << "Thank you for stopping by! Here is a summary of your transactions." << endl;
    cout << "In total, you've made " << depositcount << " deposits, " << checkcounttot << " check withdrawals, and " << atmcounttot << " ATM withdrawals." << endl;
    cout << "You were deducted " << totalfees << " in bank maitenance fees.";
    
}



int main()
{
    
	char X;
	char next = '\0';
	double initialAmount;
	double amount;
    
	CheckingAccount A;
    
	cout << "Welcome to the Bank! Please, enter your starting balance: ";
	cin >> initialAmount;

    
if (!cin.eof() && cin.good())
{
    
    A.putInitialBalance(initialAmount);
        
	do
	{
		cout << endl << endl << "What would you like to do?" << endl;
		cout << "For Deposits, Enter [D]." << endl;
		cout << "For Check Withdrawals, Enter [C]." << endl;
		cout << "For ATM Withdrawals, Enter [A]." << endl;
		cout << "For Fees, Enter [F]." << endl;
		cout << "To Exit, Enter [E]." << endl << endl;
		cout << "Please enter choice here: ";
        
		cin >> X;
        

		switch (X)
		{
            case 'D': case 'd':
            {
                cout << endl << "How much would you like to deposit? ";
                cin >> amount;
                A.calcDep(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'C': case 'c':
            {
                cout << endl << "How much would you like to withdraw? ";
                cin >> amount;
                A.calcCheck(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'A': case 'a':
            {
                cout << endl << "How much would you like to withdraw? ";
                cin >> amount;
                A.calcATM(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'F': case 'f':
            {
                A.displayFees();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'E': case 'e':
            {
                cout << "Thank you for stopping by! Here is a summary of your transactions." << endl;
                return EXIT_SUCCESS; break;
            }
                
            default:
            {
                cout << "Invalid selection. Please, try again." << endl << endl;
            }
        }
        
	}while (next == 'Y' || next == 'y');
    

	if (next == 'N' || next == 'n')
	{
		cout << "Report ending balance, total deposits, total withdrawals, and total fees.";
		return 0;
	}
}
}



Last edited on
What about using a stringstream in your class?

Each time you make a transaction, you record that transaction to the stringstream. When you exit the program, output the stringstream to cout.

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
#include <stringstream> 

class CheckingAccount
{  stringstream   ss; 
...
};

void putInitialBalance(double w) 
{ runningBalance = w; 
  // Record the initial deposit to the stringstream
  ss << "Initial Deposit = " << w << endl;
}

void CheckingAccount::calcDep(double amount)
{  //  Record the deposit to the stringstream
    ss << "Deposit made: " << amount << endl;
}

//  Add logging to stringstream for all other transactions

//  Add to displaySummary 
    cout << "Your Transaction history" << endl; 
    cout << ss.str() << endl;

//  After line 218
    A.displaySummary ();






I'm still new to C++. Would you mind explaining what that library does exactly?
http://www.cplusplus.com/doc/tutorial/basic_io/

See the "stringstream" section.
Thank you!
Topic archived. No new replies allowed.