-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoBankProgramStruct.cpp
More file actions
82 lines (73 loc) · 2.23 KB
/
DemoBankProgramStruct.cpp
File metadata and controls
82 lines (73 loc) · 2.23 KB
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
#include <iostream>
#include <string>
using namespace std;
// account struct
struct Account {
string name;
int accountNumber;
double balance;
};
// deposit function
void deposit(Account* account, double amount) {
account->balance += amount;
cout << "New balance: " << account->balance << endl;
}
// withdraw function
void withdraw(Account* account, double amount) {
if (amount > account->balance) {
cout << "Insufficient funds." << endl;
} else {
account->balance -= amount;
cout << "New balance: " << account->balance << endl;
}
}
// view account information function
void viewAccountInfo(Account* account) {
cout << "Account holder: " << account->name << endl;
cout << "Account number: " << account->accountNumber << endl;
cout << "Balance: " << account->balance << endl;
}
int main() {
// get account information from user
Account account;
cout << "Enter your name to create an account: ";
cin >> account.name;
cout << "Enter your account number: ";
cin >> account.accountNumber;
cout << "Enter your starting balance: ";
cin >> account.balance;
// perform operations
int choice;
do {
cout << endl << "1 - Deposit" << endl;
cout << "2 - Withdraw" << endl;
cout << "3 - View account information" << endl;
cout << "0 - Exit" << endl;
cout << "Your choice: ";
cin >> choice;
switch (choice) {
case 1:
double depositAmount;
cout << "Enter the amount you want to deposit: ";
cin >> depositAmount;
deposit(&account, depositAmount);
break;
case 2:
double withdrawAmount;
cout << "Enter the amount you want to withdraw: ";
cin >> withdrawAmount;
withdraw(&account, withdrawAmount);
break;
case 3:
viewAccountInfo(&account);
break;
case 0:
cout << "Exiting..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
break;
}
} while (choice != 0);
return 0;
}