Build an Bank Management System in C Language with Free Codes

Table of Contents

Introduction – Bank Management System

Hello Guys, Today we are Going to Create a Bank Management System in C Language the intermediate Level Project, Which boost your C Language Skill level. This is Console Based Project which teaches you – how banking applications functions are create.

Project Feature – Bank Management System

Here is the list of the project feature,

  • Create Account
  • Deposit
  • Withdraw
  • Check Balance

Software Used for Output

For get the output of the Bank Management System Project we used a Code::Blocks software. It is a beginner friendly and mostly used software by the C Language Developers.

Free Notes

Output – Bank Management System

 

Project Explanation

Here we explain our Project Bank Management System in brief for understand how the functions work in this,

Part – 1 Header File

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

Here we Include Three Header File which are used for input/output operations, memory allocations and string functions respectively.

Part – 2 Structure Definition

// Define structure for Bank Account
struct BankAccount {
    int accountNumber;
    char name[100];
    float balance;
};

Here the ‘struct BankAccount’ defines the structure for a bank account, which contains the three fields,

  1. ‘accountnumber’ is an integer to store the account number.
  2. ‘name’ is a character array to store account holder’s name (up to 100 characters).
  3. ‘balance’ is a float to store the account balance.

Part – 3 Function to Create Account

// Function to create a new account
void createAccount(struct BankAccount *accounts, int *numAccounts) {
    printf("Enter account number: ");
    scanf("%d", &accounts[*numAccounts].accountNumber);
    printf("Enter name: ");
    scanf("%s", accounts[*numAccounts].name);
    accounts[*numAccounts].balance = 0.0;
    (*numAccounts)++;
    printf("Account created successfully.\n");
}

This functionality is used for create a new Bank Account. Here we create a function name “createAccount’ that takes an array of ‘BankAccount’ structures and the number of existing accounts as parameters. Inside the Function, we prompt the user to enter the account number, name and initialize the balance to zero.

Part – 4 Function for Deposit Money

// Function to deposit money
void deposit(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    float amount;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Enter amount to deposit: ");
            scanf("%f", &amount);
            accounts[i].balance += amount;
            printf("Deposit successful. Current balance: %.2f\n", accounts[i].balance);
            return;
        }
    }
    printf("Account not found.\n");
}

Here we add the functionality of deposit money into an existing account. Here we create a function named ‘deposit’ that takes the array of ‘BankAccount’ structures and the number of existing account as parameter. This function allow to user enter their account numbers and the amount which they want deposit. It will then update the balance of the corresponding account.

Part – 5 Function for Withdraw Money

// Function to withdraw money
void withdraw(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    float amount;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Enter amount to withdraw: ");
            scanf("%f", &amount);
            if (amount > accounts[i].balance) {
                printf("Insufficient balance.\n");
            } else {
                accounts[i].balance -= amount;
                printf("Withdrawal successful. Current balance: %.2f\n", accounts[i].balance);
            }
            return;
        }
    }
    printf("Account not found.\n");
}

Here we add the functionality of withdrawing money from existing account. Here, we create a function named ‘withdraw’ that takes an array of ‘BankAccount’ structures and the number as the parameters from the existing accounts. in this function Firstly user enter the account number and then the amount which they want to withdraw.

Part – 6 Checking Balance Function

// Function to check balance
void checkBalance(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Current balance: %.2f\n", accounts[i].balance);
            return;
        }
    }
    printf("Account not found.\n");
}

Here we implement the function named ‘checkBalance’ which allow user to check their balance from the accounts. This function firstly takes an array of ‘BankAccount’ structures and it will take as parameters. This Function first ask the account number to the user – if user fill correct account number then it will show the balance of account.

Part – 7 Main Function

int main() {
    struct BankAccount accounts[100];
    int numAccounts = 0;
    int choice;

    do {
        printf("\nBank Management System\n");
        printf("1. Create Account\n");
        printf("2. Deposit\n");
        printf("3. Withdraw\n");
        printf("4. Check Balance\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                createAccount(accounts, &numAccounts);
                break;
            case 2:
                deposit(accounts, numAccounts);
                break;
            case 3:
                withdraw(accounts, numAccounts);
                break;
            case 4:
                checkBalance(accounts, numAccounts);
                break;
            case 5:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice.\n");
        }
    } while (choice != 5);

    return 0;
}

Here, this initializes an array of “BankAccount’ structures named ‘accounts’ with a capacity of 100 accounts and an integer variable ‘numAccounts’ to keep track of the number of existing accounts. And it represents the menu-driven interface by using a “do-while” Loop which allows to user to choose from the allowing options,

  1. Create Account
  2. Deposit
  3. Withdraw
  4. Check Balance
  5. Exit

Here Based on the user’s choice, the corresponding function is called. The loop continues until the user choose to exit the program.

Project Codes

Here the Complete Project Codes,

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

// Define structure for Bank Account
struct BankAccount {
    int accountNumber;
    char name[100];
    float balance;
};

// Function to create a new account
void createAccount(struct BankAccount *accounts, int *numAccounts) {
    printf("Enter account number: ");
    scanf("%d", &accounts[*numAccounts].accountNumber);
    printf("Enter name: ");
    scanf("%s", accounts[*numAccounts].name);
    accounts[*numAccounts].balance = 0.0;
    (*numAccounts)++;
    printf("Account created successfully.\n");
}

// Function to deposit money
void deposit(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    float amount;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Enter amount to deposit: ");
            scanf("%f", &amount);
            accounts[i].balance += amount;
            printf("Deposit successful. Current balance: %.2f\n", accounts[i].balance);
            return;
        }
    }
    printf("Account not found.\n");
}

// Function to withdraw money
void withdraw(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    float amount;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Enter amount to withdraw: ");
            scanf("%f", &amount);
            if (amount > accounts[i].balance) {
                printf("Insufficient balance.\n");
            } else {
                accounts[i].balance -= amount;
                printf("Withdrawal successful. Current balance: %.2f\n", accounts[i].balance);
            }
            return;
        }
    }
    printf("Account not found.\n");
}

// Function to check balance
void checkBalance(struct BankAccount *accounts, int numAccounts) {
    int accNum;
    printf("Enter account number: ");
    scanf("%d", &accNum);
    for (int i = 0; i < numAccounts; i++) {
        if (accounts[i].accountNumber == accNum) {
            printf("Current balance: %.2f\n", accounts[i].balance);
            return;
        }
    }
    printf("Account not found.\n");
}

int main() {
    struct BankAccount accounts[100];
    int numAccounts = 0;
    int choice;

    do {
        printf("\nBank Management System\n");
        printf("1. Create Account\n");
        printf("2. Deposit\n");
        printf("3. Withdraw\n");
        printf("4. Check Balance\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                createAccount(accounts, &numAccounts);
                break;
            case 2:
                deposit(accounts, numAccounts);
                break;
            case 3:
                withdraw(accounts, numAccounts);
                break;
            case 4:
                checkBalance(accounts, numAccounts);
                break;
            case 5:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice.\n");
        }
    } while (choice != 5);

    return 0;
}

 

Conclusion

Here we learn about How Create an Bank Management System in C Language, and how these functions work and how we properly used switch case statements and do-while loop.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top