Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int balance1 = 0;
  5. int balance2 = 0;
  6. int balance3 = 0;
  7. int balance4 = 0;
  8. int balance5 = 0;
  9.  
  10. void sendTransactions() {
  11. printf("Transactions Available\n");
  12. printf("1. Deposit\n");
  13. printf("2. Withdraw\n");
  14. printf("3. Transfer Funds\n");
  15. printf("4. Check Balance\n");
  16. printf("5. Main Menu\n");
  17. printf("*********************\n");
  18. }
  19.  
  20. char getName(int id) {
  21. switch(id) {
  22. case 1:
  23. return 'RJ Dequina';
  24. break;
  25. case 2:
  26. return 'Raymart Sarmiento';
  27. break;
  28. case 3:
  29. return 'Arreza Ronnel';
  30. break;
  31. case 4:
  32. return 'Maersk Caddarao';
  33. break;
  34. case 5:
  35. return 'Clyde Lamina';
  36. break;
  37. }
  38. }
  39.  
  40. void formatMessage(int id, char text[], int balance) {
  41. switch(id) {
  42. case 1:
  43. printf("*********************\n");
  44. printf("Account Name: RJ Dequina\n");
  45. printf("Current Balance: %d\n", balance1);
  46. printf("%s", text);
  47. printf("\n");
  48. printf("*********************\n");
  49. break;
  50. case 2:
  51. printf("*********************\n");
  52. printf("Account Name: Raymart Sarmiento\n");
  53. printf("Current Balance: %d\n", balance2);
  54. printf("%s", text);
  55. printf("\n");
  56. printf("*********************\n");
  57. break;
  58. case 3:
  59. printf("*********************\n");
  60. printf("Account Name: Arreza Ronnel\n");
  61. printf("Current Balance: %d\n", balance3);
  62. printf("%s", text);
  63. printf("\n");
  64. printf("*********************\n");
  65. break;
  66. case 4:
  67. printf("*********************\n");
  68. printf("Account Name: Maersk Caddarao\n");
  69. printf("Current Balance: %d\n", balance4);
  70. printf("%s", text);
  71. printf("\n");
  72. printf("*********************\n");
  73. break;
  74. case 5:
  75. printf("*********************\n");
  76. printf("Account Name: Clyde Lamina\n");
  77. printf("Current Balance: %d\n", balance5);
  78. printf("%s", text);
  79. printf("\n");
  80. printf("*********************\n");
  81. break;
  82. }
  83. }
  84.  
  85. void clearScreen() {
  86. system("cls");
  87. }
  88.  
  89. void dealTransaction(int id, int balance) {
  90. int choice;
  91. int amount;
  92. int chosenId;
  93. scanf("%d", &choice);
  94. switch(choice) {
  95. case 1:
  96. amount = 0;
  97. formatMessage(id, "Enter Amount to Deposit", balance);
  98. scanf("%d", &amount);
  99. balance += amount;
  100. formatMessage(id, "", balance);
  101. sendTransactions();
  102. dealTransaction(id, balance);
  103. break;
  104. case 2:
  105. amount = 0;
  106. formatMessage(id, "Enter Amount to Withdraw", balance);
  107. scanf("%d", &amount);
  108. if(amount > balance) {
  109. formatMessage(id, "Unsuccessful Transaction", balance);
  110. sendTransactions();
  111. dealTransaction(id, balance);
  112. } else {
  113. balance -= amount;
  114. formatMessage(id, "Successful Transaction", balance);
  115. sendTransactions();
  116. dealTransaction(id, balance);
  117. }
  118. formatMessage(id, "", balance);
  119. sendTransactions();
  120. dealTransaction(id, balance);
  121. break;
  122. case 3:
  123. amount = 0;
  124. formatMessage(id, "Enter account number you wish to transfer funds", balance);
  125. scanf("%d", &amount);
  126. if(amount == id) {
  127. formatMessage(id, "You cannot transfer to yourself", balance);
  128. sendTransactions();
  129. dealTransaction(id, balance);
  130. }else {
  131. if(amount < 1 || amount > 5) {
  132. formatMessage(id, "Unsuccessful Transaction", balance);
  133. sendTransactions();
  134. dealTransaction(id, balance);
  135. }else {
  136. int number = 0;
  137. formatMessage(id, "How much you want to transfer to this account", balance);
  138. scanf("%d", &number);
  139. if(number > balance) {
  140. formatMessage(id, "Inssuficient Balance", balance);
  141. sendTransactions();
  142. dealTransaction(id, balance);
  143. }else {
  144. switch(amount) {
  145. case 1:
  146. balance1+=number;
  147. break;
  148. case 2:
  149. balance2+=number;
  150. break;
  151. case 3:
  152. balance3+=number;
  153. break;
  154. case 4:
  155. balance4+=number;
  156. break;
  157. case 5:
  158. balance5+=number;
  159. break;
  160. }
  161. balance-=number;
  162. formatMessage(id, "Successful Transaction", balance);
  163. sendTransactions();
  164. dealTransaction(id, balance);
  165. }
  166. }
  167. }
  168. break;
  169. case 4:
  170. formatMessage(id, "", balance);
  171. sendTransactions();
  172. dealTransaction(id, balance);
  173. break;
  174. case 5:
  175. printf("*********************\n");
  176. printf("Enter any account ID to start the transaction\n");
  177. printf("1. RJ Dequina\n");
  178. printf("2. Raymart Sarmiento\n");
  179. printf("3. Arreza Ronnel\n");
  180. printf("4. Maersk Caddarao\n");
  181. printf("5. Clyde Lamina\n");
  182. printf("*********************\n");
  183. scanf("%d", &chosenId);
  184. switch(chosenId) {
  185. case 1:
  186. formatMessage(1, "", balance1);
  187. sendTransactions();
  188. dealTransaction(1, balance1);
  189. break;
  190. case 2:
  191. formatMessage(2, "", balance2);
  192. sendTransactions();
  193. dealTransaction(2, balance2);
  194. break;
  195. case 3:
  196. formatMessage(3, "", balance3);
  197. sendTransactions();
  198. dealTransaction(3, balance3);
  199. break;
  200. case 4:
  201. formatMessage(4, "", balance4);
  202. sendTransactions();
  203. dealTransaction(4, balance4);
  204. break;
  205. case 5:
  206. formatMessage(5, "", balance5);
  207. sendTransactions();
  208. dealTransaction(5, balance5);
  209. break;
  210. }
  211. break;
  212. }
  213. }
  214.  
  215. int main() {
  216. int chosenId;
  217. printf("*********************\n");
  218. printf("Enter any account ID to start the transaction\n");
  219. printf("1. RJ Dequina\n");
  220. printf("2. Raymart Sarmiento\n");
  221. printf("3. Arreza Ronnel\n");
  222. printf("4. Maersk Caddarao\n");
  223. printf("5. Clyde Lamina\n");
  224. printf("*********************\n");
  225. scanf("%d", &chosenId);
  226. switch(chosenId) {
  227. case 1:
  228. formatMessage(1, "", balance1);
  229. sendTransactions();
  230. dealTransaction(1, balance1);
  231. break;
  232. case 2:
  233. formatMessage(2, "", balance2);
  234. sendTransactions();
  235. dealTransaction(2, balance2);
  236. break;
  237. case 3:
  238. formatMessage(3, "", balance3);
  239. sendTransactions();
  240. dealTransaction(3, balance3);
  241. break;
  242. case 4:
  243. formatMessage(4, "", balance4);
  244. sendTransactions();
  245. dealTransaction(4, balance4);
  246. break;
  247. case 5:
  248. formatMessage(5, "", balance5);
  249. sendTransactions();
  250. dealTransaction(5, balance5);
  251. break;
  252. }
  253. return (0);
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement