pranjal1805

Function-4

May 15th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. #include<stdio.h>
  2. const int MAXSIZE=100;
  3. float checking_balance(float a[],int x);
  4. float deposit(float a[], int x, int y);
  5. float withdraw(float a[], int x, int y);
  6. float transfer();
  7. int main()
  8. {  
  9.     float account[MAXSIZE];
  10.     int n,e,f,g;
  11.     printf("Enter number of customers:");
  12.     scanf(" %d", &n);
  13.     printf("Enter amount in each customer's account:");
  14.     char c;
  15.     for(int i=1;i<=n;i++)
  16.     {
  17.         scanf("%f", &account[i]);
  18.     }
  19.     printf("Select one of the following ATM operations\n");
  20.     printf("Checking the balance amount (B)\n");
  21.     printf("Withdrawing the amount from the account (W)\n");
  22.     printf("Depositing the amount to the account (D)\n");
  23.     printf("Transfer (T)\n");
  24.     printf("Enter choice:\n");
  25.     scanf(" %c", &c);
  26.     switch(c)
  27.     {
  28.         case 'B':
  29.         {  
  30.             printf("Enter debit account number:");
  31.             scanf(" %d", &e);
  32.             printf("Current balance in account #%d is %f", e,checking_balance(account,e));
  33.             break;
  34.         }
  35.        
  36.         case 'D':
  37.         {
  38.             printf("Enter credit account number:");
  39.             scanf(" %d", &e);
  40.             printf("Enter the amount to be deposited:");
  41.             scanf(" %d", &f);
  42.             printf("Current balance in account #%d is %f", e,deposit(account,e,f));
  43.             break;
  44.         }
  45.        
  46.         case 'W':
  47.         {  
  48.             printf("Enter debit account number:");
  49.             scanf(" %d", &e);
  50.             printf("Enter the amount to be withdrawn:");
  51.             scanf(" %d", &f);
  52.             printf("Current balance in account #%d is %f", e,withdraw(account,e,f));
  53.             break;
  54.         }
  55.         case 'T':
  56.         {  
  57.             printf("Enter debit account number:");
  58.             scanf(" %d", &e);
  59.             printf("Enter credit account number:");
  60.             scanf(" %d", &g);
  61.             printf("Enter amount to deposit:");
  62.             scanf(" %d", &f);
  63.             transfer(account,e,g,f);
  64.             break;
  65.         }
  66.     }
  67.     return 0;
  68. }
  69.  
  70. float checking_balance(float a[],int x)
  71. {
  72.     return a[x];
  73. }
  74.  
  75. float deposit(float a[], int x, int y)
  76. {
  77.     a[x]=a[x]+y;
  78.     return checking_balance(a,x);
  79. }
  80.  
  81. float withdraw(float a[], int x, int y)
  82. {
  83.    
  84.     if((a[x]-y)>=0)
  85.     {
  86.         a[x]=a[x]-y;
  87.         return checking_balance(a,x);
  88.     }
  89.    
  90.     else
  91.     {  
  92.         printf("Sorry the transaction isn't possible\n");
  93.         return checking_balance(a,x);
  94.        
  95.     }
  96. }
  97.  
  98. float transfer(float a[],int x, int y,int z)
  99. {  
  100.     if((a[x]-z)>=0)
  101.     {
  102.         printf("Current balance in account #%d is %f\n", x,withdraw(a,x,z));
  103.         printf("Current balance in account #%d is %f\n", y,deposit(a,y,z));
  104.     }
  105.    
  106.     else
  107.     {
  108.         printf("Sorry the transaction isn't possible\n");
  109.         printf("Current balance in account #%d is %f\n", x,checking_balance(a,x));
  110.         printf("Current balance in account #%d is %f\n", y,checking_balance(a,y));
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment