Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int menu(void);
  5. /* #1 */ void new_accounts(int *, float *, int *, float *);
  6. /* #2 */ void summary(int, float, int, float);
  7. /* #3 */ void withdraw(int, float *, float);
  8. /* #4 */ void deposit(int, float *, float);
  9. /* #5 */ void transfer(int, float *, int, float *, float);
  10. /* #6 */ void exchange(int, float *, int, float *);
  11. /* #7 */ int *high_balance(int *, float, int *, float, float *);
  12. /* #8 */ void reset(float *, float *);
  13. /* #9 */ void change(int *, int);
  14.  
  15.  
  16. int main(void){
  17.  
  18. menu();
  19. return 0;
  20. }
  21.  
  22.  
  23. int menu (void){
  24. int choice;
  25. //menu Declarations
  26.  
  27. int accountNum1;
  28. int accountNum2;
  29. float balance1;
  30. float balance2;
  31. //newAccounts Declarations
  32.  
  33. int tmp=0;
  34. //withdraw Declaraions
  35. while(1==1){
  36. printf("\n--------------------------------\nMain Menu\n");
  37. printf("\n1 New Accounts\n2 All Accounts\n3 Withdraw\n4 Deposit\n5 Transfer Fund\n6 Exchange Balance\n7 High Balance");
  38. printf("\n8 Reset All Balance\n9 Change Account Number\n0 Exit\n");
  39. //menu format
  40.  
  41. scanf("%d", &choice);
  42. switch(choice){
  43. case 1: new_accounts(&accountNum1, &balance1, &accountNum2, &balance2);
  44. break;
  45. case 2: summary(accountNum1, balance1, accountNum2, balance2);
  46. break;
  47. case 3:
  48.  
  49. while((tmp!=accountNum1)&&(tmp!=accountNum2)){
  50.  
  51. printf("Enter an account to withdraw (%d or %d?): ", accountNum1,accountNum2);
  52. scanf("%d", &tmp);
  53.  
  54.  
  55. if((tmp!=accountNum1)&&(tmp!=accountNum2))
  56.  
  57. printf("invalid account number.\n");
  58.  
  59.  
  60. }
  61. printf("Enter an amount to withdraw: ");
  62. scanf("%d", &tmp);
  63.  
  64. //input validation
  65.  
  66. if (tmp== accountNum1){
  67. withdraw(accountNum1, &balance1, tmp);
  68. }
  69. else{
  70. withdraw(accountNum2, &balance2, tmp);
  71. }
  72.  
  73. break;
  74.  
  75. case 4:
  76. while((tmp!=accountNum1)||(tmp!=accountNum2)){
  77.  
  78. printf("Enter an account to deposit (%d or %d?): ", accountNum1,accountNum2);
  79. scanf("%d", &tmp);
  80.  
  81. printf("Enter an amount to deposit: ");
  82. scanf("%d", &tmp);
  83.  
  84. if((tmp!=accountNum1)&&(tmp!=accountNum2))
  85. printf("invalid account number.\n");
  86. }
  87. //input validation
  88.  
  89. if (tmp== accountNum1){
  90. withdraw(accountNum1, &balance1, tmp);
  91. }
  92. else{
  93. withdraw(accountNum2, &balance2, tmp);
  94. }
  95.  
  96. break;
  97. /*
  98. case 5: transfer();
  99. break;
  100. case 6: exchange();
  101. break;
  102. case 7: *high_balance();
  103. break;
  104. case 8: reset();
  105. break;
  106. case 9: change();
  107. break;
  108. */
  109. case 0: exit(0);
  110. printf("Goodbye!");
  111. break;
  112. default: printf("invalid input");
  113. break;
  114. }
  115.  
  116. }
  117. }
  118.  
  119.  
  120. void new_accounts(int* accountNum1, float*balance1, int*accountNum2, float*balance2){
  121. int flag=0;
  122. while(flag==0){
  123.  
  124. srand(time(0));
  125.  
  126. *accountNum1= rand()%59+54;
  127. *balance1= rand()%999+(-100);
  128.  
  129. *accountNum2= rand()%59+54;
  130. *balance2= rand()%999+(-100);
  131.  
  132. if(accountNum1== accountNum2){
  133. flag=0;
  134. }
  135. else{
  136. flag=1;
  137. }
  138. }
  139. printf(">>>>Accounts created.");
  140. }
  141.  
  142. void summary(int accountNum1, float balance1, int accountNum2, float balance2){
  143. printf("\n>>>>%5d: $%-10.2f", accountNum1, balance1);
  144. printf("\n>>>>%5d: $%-10.2f", accountNum2, balance2);
  145. }
  146.  
  147.  
  148. void withdraw(int accountNum, float * newBalance, float withdrawl ){
  149.  
  150. printf(">>>> Account %d has changed from %.2f to %.2f", accountNum, *newBalance, *newBalance-withdrawl);
  151. *newBalance-= withdrawl;
  152.  
  153. }
  154.  
  155. void deposit(int accountNum, float * newBalance, float withdrawl ){
  156.  
  157. printf(">>>> Account %d has changed from %f to %f", accountNum, *newBalance, *newBalance-withdrawl);
  158. *newBalance-= withdrawl;
  159.  
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement