luc079.c (2495B)
1 /* Create a structure for bank customers (Acc no, Name, Balance). Write functions to print low balance customers and handle deposits/withdrawals. 2 */ 3 /* Let Us C, Chap- 17 (Structures), Qn No.: B(b) */ 4 5 /* This file is auto-generated by a bot. */ 6 /* This code is not compiled; it is for reference only. */ 7 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdlib.h> 12 13 struct customer 14 { 15 int acc_no; 16 char name[50]; 17 float balance; 18 }; 19 20 void print_low_balance(struct customer *c, int n); 21 void transaction(struct customer *c, int n, int acc, float amount, int code); 22 23 int main() 24 { 25 struct customer bank[200] = { 26 {1001, "Alice", 5000.0}, 27 {1002, "Bob", 500.0}, 28 {1003, "Charlie", 1200.0}, 29 {1004, "David", 800.0}, 30 {1005, "Eve", 2000.0} 31 }; 32 int n = 5; 33 int acc, code; 34 float amt; 35 36 // Task 1: Low Balance 37 printf("--- Customers with Balance < Rs. 1000 ---\n"); 38 print_low_balance(bank, n); 39 40 // Task 2: Transaction 41 printf("\n--- Transaction Menu ---\n"); 42 printf("Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): "); 43 scanf("%d %f %d", &acc, &amt, &code); 44 45 transaction(bank, n, acc, amt, code); 46 47 return 0; 48 } 49 50 void print_low_balance(struct customer *c, int n) 51 { 52 int i; 53 for (i = 0; i < n; i++) 54 { 55 if (c[i].balance < 1000) 56 { 57 printf("Acc: %d, Name: %s, Bal: %.2f\n", c[i].acc_no, c[i].name, c[i].balance); 58 } 59 } 60 } 61 62 void transaction(struct customer *c, int n, int acc, float amount, int code) 63 { 64 int i, found = 0; 65 for (i = 0; i < n; i++) 66 { 67 if (c[i].acc_no == acc) 68 { 69 found = 1; 70 if (code == 1) // Deposit 71 { 72 c[i].balance += amount; 73 printf("Deposit successful. New Balance: %.2f\n", c[i].balance); 74 } 75 else if (code == 0) // Withdraw 76 { 77 if (c[i].balance - amount < 1000) 78 { 79 printf("The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n"); 80 } 81 else 82 { 83 c[i].balance -= amount; 84 printf("Withdrawal successful. New Balance: %.2f\n", c[i].balance); 85 } 86 } 87 else 88 { 89 printf("Invalid transaction code.\n"); 90 } 91 break; 92 } 93 } 94 if (!found) printf("Account number not found.\n"); 95 }