Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. /*
  2. Richard Morgan
  3.  
  4. CIS 125 - 71
  5.  
  6. Banking Program Part 1
  7. This program will simulate a bank.
  8. Update 1: Adding branching logic
  9. */
  10.  
  11. #include <iostream>
  12. #include <string>
  13.  
  14. using namespace std;
  15.  
  16. int mainMenu ();
  17. void showBalances (float, float);
  18. float getDeposit (float, string);
  19. float deposit (float, float);
  20. float getWithdrawl (float, string);
  21. float withdrawl (float, float);
  22. float getTransferAmount ();
  23. void transfer (float &, float &);
  24.  
  25. int main ()
  26. {
  27. //Declaration Block
  28. float savings = 567.82;
  29. float checking = 1947.29;
  30. int userEntry = 0;
  31. int accountSelection = 0;
  32.  
  33. userEntry = mainMenu ();
  34.  
  35. if (userEntry == 1) //View Balances
  36. {
  37. showBalances (savings, checking);
  38. }
  39. else
  40. if (userEntry == 2) //Deposit
  41. {
  42. //cout << "Inside Deposit" << endl;
  43. cout << "Welcome to the deposit function." << endl;
  44. cout << "Enter the account you wish to deposit into: " << endl;
  45. cout << "1. Savings" << endl;
  46. cout << "2. Checking" << endl;
  47. cin >> accountSelection;
  48.  
  49. switch (accountSelection)
  50. {
  51. case 1:
  52. savings = getDeposit (savings, "savings");
  53. break;
  54. case 2:
  55. checking = getDeposit (checking, "checking");
  56. break;
  57. default:
  58. cout << "Bad entry. Goodbye!" << endl;
  59. }
  60. showBalances (savings, checking);
  61. }
  62. else
  63. if (userEntry == 3) //Withdrawl
  64. {
  65. //cout << "Inside Withdrawl" << endl;
  66. cout << "Welcome to the withdrawl function." << endl;
  67. cout << "Enter the account you wish to withdraw from: " << endl;
  68. cout << "1. Savings" << endl;
  69. cout << "2. Checking" << endl;
  70. cin >> accountSelection;
  71.  
  72. switch (accountSelection)
  73. {
  74. case 1:
  75. savings = getWithdrawl (savings, "savings");
  76. break;
  77. case 2:
  78. checking = getWithdrawl (checking, "checking");
  79. break;
  80. default:
  81. cout << "Bad entry. Goodbye!" << endl;
  82. }
  83. showBalances (savings, checking);
  84. }
  85. else
  86. if (userEntry == 4) //Transfer
  87. {
  88. //cout << "Inside Transfer" << endl;
  89. cout << "Welcome to the transfer menu." << endl;
  90. transfer (savings, checking);
  91. showBalances (savings, checking);
  92. }
  93. else
  94. if (userEntry == 5) //Exit
  95. {
  96. cout << "Thank you for visiting the HFC Banking System." << endl;
  97. cout << "Have a great day!" << endl;
  98. }
  99. else //Bad Entry
  100. {
  101. cout << "Unrecognized entry. Goodbye!" << endl;
  102. }
  103.  
  104. system ("pause");
  105.  
  106. return 0;
  107. }
  108.  
  109. int mainMenu ()
  110. {
  111. int choice = 0;
  112.  
  113. cout << "Welcome to the HFC Banking System." << endl;
  114. cout << "Please make your selection: " << endl;
  115. cout << "1. View Account Balances" << endl;
  116. cout << "2. Deposit" << endl;
  117. cout << "3. Withdrawl" << endl;
  118. cout << "4. Transfer" << endl;
  119. cout << "5. Exit" << endl;
  120. cin >> choice;
  121.  
  122. return choice;
  123. }
  124.  
  125. void showBalances (float sav, float check)
  126. {
  127. cout << "Balance Inquiry: " << endl;
  128. cout << "Savings Balance: $" << sav << endl;
  129. cout << "Checking Balance: $" << check << endl;
  130. }
  131.  
  132. float getDeposit (float balance, string account)
  133. {
  134. float dep = 0.00;
  135.  
  136. cout << "Please enter the amount you wish to deposit into " << account << ": $";
  137. cin >> dep;
  138.  
  139. balance = deposit (balance, dep);
  140.  
  141. return balance;
  142. }
  143.  
  144. float deposit (float balance, float dep)
  145. {
  146. balance = balance + dep;
  147.  
  148. return balance;
  149. }
  150.  
  151. float getWithdrawl (float balance, string account)
  152. {
  153. float with = 0.00;
  154.  
  155. cout << "Please enter the amount you wish to withdraw from " << account << ": $";
  156. cin >> with;
  157.  
  158. balance = withdrawl (balance, with);
  159.  
  160. return balance;
  161. }
  162.  
  163. float withdrawl (float balance, float with)
  164. {
  165. balance = balance - with;
  166.  
  167. return balance;
  168. }
  169.  
  170. void transfer (float &savings, float &checking)
  171. {
  172. int account = 0;
  173. float amount = 0.00;
  174.  
  175. cout << "Please enter the account you wish to transfer from: " << endl;
  176. showBalances (savings, checking);
  177. cout << "1. Savings" << endl;
  178. cout << "2. Checking" << endl;
  179. cin >> account;
  180.  
  181. if (account == 1) //Transfer from Savings
  182. {
  183. amount = getTransferAmount ();
  184. savings = withdrawl (savings, amount);
  185. checking = deposit (checking, amount);
  186. }
  187. else
  188. if (account == 2) //Transfer from Checking
  189. {
  190. amount = getTransferAmount ();
  191. checking = withdrawl (checking, amount);
  192. savings = deposit (savings, amount);
  193. }
  194. else
  195. {
  196. cout << "Bad entry. Goodbye!" << endl;
  197. }
  198. }
  199.  
  200. float getTransferAmount ()
  201. {
  202. float amt = 0.00;
  203.  
  204. cout << "Enter the amount you wish to transfer: $";
  205. cin >> amt;
  206.  
  207. return amt;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement