Cover Image for Bank Account Management System in C
80 views

Bank Account Management System in C

Creating a bank account management system in C is a complex task, and it typically involves handling multiple aspects, such as creating and managing accounts, performing transactions, and maintaining account details. Here, I’ll provide you with a simplified outline and code structure to get you started on a basic bank account management system. This example does not include extensive error handling or data storage (e.g., using files or databases) for simplicity.

C
#include <stdio.h>
#include <stdlib.h>

// Structure to represent a bank account
struct Account {
    int accountNumber;
    char accountHolderName[100];
    float balance;
};

// Function to create a new bank account
struct Account createAccount(int accountNumber, char accountHolderName[], float initialBalance) {
    struct Account account;
    account.accountNumber = accountNumber;
    strcpy(account.accountHolderName, accountHolderName);
    account.balance = initialBalance;
    return account;
}

// Function to display account details
void displayAccount(struct Account account) {
    printf("Account Number: %d\n", account.accountNumber);
    printf("Account Holder Name: %s\n", account.accountHolderName);
    printf("Balance: %.2f\n", account.balance);
}

// Function to deposit money into an account
void deposit(struct Account* account, float amount) {
    account->balance += amount;
    printf("Deposited %.2f. New balance: %.2f\n", amount, account->balance);
}

// Function to withdraw money from an account
void withdraw(struct Account* account, float amount) {
    if (account->balance >= amount) {
        account->balance -= amount;
        printf("Withdrawn %.2f. New balance: %.2f\n", amount, account->balance);
    } else {
        printf("Insufficient balance. Withdrawal failed.\n");
    }
}

int main() {
    struct Account accounts[10];  // Array to store accounts (up to 10 accounts)
    int accountCount = 0;        // Current number of accounts

    while (1) {
        int choice;
        printf("\nBank Account Management System Menu:\n");
        printf("1. Create Account\n");
        printf("2. Display Account Details\n");
        printf("3. Deposit Money\n");
        printf("4. Withdraw Money\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1: {
                if (accountCount < 10) {
                    int accountNumber;
                    char accountHolderName[100];
                    float initialBalance;

                    printf("Enter Account Number: ");
                    scanf("%d", &accountNumber);
                    printf("Enter Account Holder Name: ");
                    scanf("%s", accountHolderName);
                    printf("Enter Initial Balance: ");
                    scanf("%f", &initialBalance);

                    accounts[accountCount] = createAccount(accountNumber, accountHolderName, initialBalance);
                    accountCount++;

                    printf("Account created successfully.\n");
                } else {
                    printf("Maximum account limit reached. Cannot create more accounts.\n");
                }
                break;
            }
            case 2: {
                int accountNumber;
                printf("Enter Account Number: ");
                scanf("%d", &accountNumber);

                int found = 0;
                for (int i = 0; i < accountCount; i++) {
                    if (accounts[i].accountNumber == accountNumber) {
                        displayAccount(accounts[i]);
                        found = 1;
                        break;
                    }
                }

                if (!found) {
                    printf("Account not found.\n");
                }
                break;
            }
            case 3: {
                int accountNumber;
                float amount;
                printf("Enter Account Number: ");
                scanf("%d", &accountNumber);

                int found = 0;
                for (int i = 0; i < accountCount; i++) {
                    if (accounts[i].accountNumber == accountNumber) {
                        printf("Enter Deposit Amount: ");
                        scanf("%f", &amount);
                        deposit(&accounts[i], amount);
                        found = 1;
                        break;
                    }
                }

                if (!found) {
                    printf("Account not found.\n");
                }
                break;
            }
            case 4: {
                int accountNumber;
                float amount;
                printf("Enter Account Number: ");
                scanf("%d", &accountNumber);

                int found = 0;
                for (int i = 0; i < accountCount; i++) {
                    if (accounts[i].accountNumber == accountNumber) {
                        printf("Enter Withdrawal Amount: ");
                        scanf("%f", &amount);
                        withdraw(&accounts[i], amount);
                        found = 1;
                        break;
                    }
                }

                if (!found) {
                    printf("Account not found.\n");
                }
                break;
            }
            case 5:
                exit(0);
            default:
                printf("Invalid choice. Please try again.\n");
        }
    }

    return 0;
}

In this simplified example:

  • You can create up to 10 bank accounts, each with a unique account number, account holder name, and initial balance.
  • You can display account details, deposit money into an account, and withdraw money from an account.

Please note that this is a basic illustration of a bank account management system for educational purposes. In a real-world scenario, you would typically use more advanced techniques for data storage (e.g., databases), user authentication, and error handling.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS