Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Richard Morgan
- CIS 125 - 71
- Banking Program Part 1
- This program will simulate a bank.
- Update 1: Adding branching logic
- */
- #include <iostream>
- #include <string>
- using namespace std;
- int mainMenu ();
- void showBalances (float, float);
- float getDeposit (float, string);
- float deposit (float, float);
- float getWithdrawl (float, string);
- float withdrawl (float, float);
- float getTransferAmount ();
- void transfer (float &, float &);
- int main ()
- {
- //Declaration Block
- float savings = 567.82;
- float checking = 1947.29;
- int userEntry = 0;
- int accountSelection = 0;
- userEntry = mainMenu ();
- if (userEntry == 1) //View Balances
- {
- showBalances (savings, checking);
- }
- else
- if (userEntry == 2) //Deposit
- {
- //cout << "Inside Deposit" << endl;
- cout << "Welcome to the deposit function." << endl;
- cout << "Enter the account you wish to deposit into: " << endl;
- cout << "1. Savings" << endl;
- cout << "2. Checking" << endl;
- cin >> accountSelection;
- switch (accountSelection)
- {
- case 1:
- savings = getDeposit (savings, "savings");
- break;
- case 2:
- checking = getDeposit (checking, "checking");
- break;
- default:
- cout << "Bad entry. Goodbye!" << endl;
- }
- showBalances (savings, checking);
- }
- else
- if (userEntry == 3) //Withdrawl
- {
- //cout << "Inside Withdrawl" << endl;
- cout << "Welcome to the withdrawl function." << endl;
- cout << "Enter the account you wish to withdraw from: " << endl;
- cout << "1. Savings" << endl;
- cout << "2. Checking" << endl;
- cin >> accountSelection;
- switch (accountSelection)
- {
- case 1:
- savings = getWithdrawl (savings, "savings");
- break;
- case 2:
- checking = getWithdrawl (checking, "checking");
- break;
- default:
- cout << "Bad entry. Goodbye!" << endl;
- }
- showBalances (savings, checking);
- }
- else
- if (userEntry == 4) //Transfer
- {
- //cout << "Inside Transfer" << endl;
- cout << "Welcome to the transfer menu." << endl;
- transfer (savings, checking);
- showBalances (savings, checking);
- }
- else
- if (userEntry == 5) //Exit
- {
- cout << "Thank you for visiting the HFC Banking System." << endl;
- cout << "Have a great day!" << endl;
- }
- else //Bad Entry
- {
- cout << "Unrecognized entry. Goodbye!" << endl;
- }
- system ("pause");
- return 0;
- }
- int mainMenu ()
- {
- int choice = 0;
- cout << "Welcome to the HFC Banking System." << endl;
- cout << "Please make your selection: " << endl;
- cout << "1. View Account Balances" << endl;
- cout << "2. Deposit" << endl;
- cout << "3. Withdrawl" << endl;
- cout << "4. Transfer" << endl;
- cout << "5. Exit" << endl;
- cin >> choice;
- return choice;
- }
- void showBalances (float sav, float check)
- {
- cout << "Balance Inquiry: " << endl;
- cout << "Savings Balance: $" << sav << endl;
- cout << "Checking Balance: $" << check << endl;
- }
- float getDeposit (float balance, string account)
- {
- float dep = 0.00;
- cout << "Please enter the amount you wish to deposit into " << account << ": $";
- cin >> dep;
- balance = deposit (balance, dep);
- return balance;
- }
- float deposit (float balance, float dep)
- {
- balance = balance + dep;
- return balance;
- }
- float getWithdrawl (float balance, string account)
- {
- float with = 0.00;
- cout << "Please enter the amount you wish to withdraw from " << account << ": $";
- cin >> with;
- balance = withdrawl (balance, with);
- return balance;
- }
- float withdrawl (float balance, float with)
- {
- balance = balance - with;
- return balance;
- }
- void transfer (float &savings, float &checking)
- {
- int account = 0;
- float amount = 0.00;
- cout << "Please enter the account you wish to transfer from: " << endl;
- showBalances (savings, checking);
- cout << "1. Savings" << endl;
- cout << "2. Checking" << endl;
- cin >> account;
- if (account == 1) //Transfer from Savings
- {
- amount = getTransferAmount ();
- savings = withdrawl (savings, amount);
- checking = deposit (checking, amount);
- }
- else
- if (account == 2) //Transfer from Checking
- {
- amount = getTransferAmount ();
- checking = withdrawl (checking, amount);
- savings = deposit (savings, amount);
- }
- else
- {
- cout << "Bad entry. Goodbye!" << endl;
- }
- }
- float getTransferAmount ()
- {
- float amt = 0.00;
- cout << "Enter the amount you wish to transfer: $";
- cin >> amt;
- return amt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement