Banking Management System in C Language

In this tutorial, we will build a simple Banking Management System in C Language. While building this project, you will learn core programming concepts, data structure handling, and memory management.

Objective

The project is designed to mimic a basic banking system. The features offered include: 

  1. Creating a new account 
  2. Checking an account's balance 
  3. Depositing money into an account 
  4. Withdrawing money from an account 
  5. Displaying the details of an account 
  6. Showing details of all accounts

Implementation

1. Struct and Global Declarations:

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

typedef struct {
    int accountNumber;
    char name[100];
    float balance;
} BankAccount;

BankAccount accounts[10];
int accountCount = 0;
BankAccount Struct: This struct represents an individual bank account. It has three fields: 
  • accountNumber: A unique identifier for each account. 
  • name: The name associated with the account. 
  • balance: The amount of money present in the account. 
accounts Array: This is an array of BankAccount structs, holding up to 10 accounts. 
accountCount: A global variable used to keep track of the number of accounts created.

2. Function Declarations:

void createAccount();
void displayAccount(int accNo);
float checkBalance(int accNo);
void deposit(int accNo, float amount);
void withdraw(int accNo, float amount);
void displayAllAccounts();

3. Function Definitions:

createAccount(): This function allows users to create a new account by providing a name and initial balance. The account number is automatically generated. 

displayAccount(int accNo): Given an account number, this function displays the details of the corresponding account. 

checkBalance(int accNo): This function returns the balance of the specified account number.

deposit(int accNo, float amount): Allows users to deposit a specified amount into an account. It increases the balance of the given account by the provided amount. 

withdraw(int accNo, float amount): Allows users to withdraw a certain amount from an account. If the account has sufficient balance, the amount is deducted; otherwise, an "Insufficient funds" message is shown. 

displayAllAccounts(): Displays details of all accounts present in the system.

Here is the complete code:

void createAccount() {
    if(accountCount < 10) {
        printf("Enter Name: ");
        scanf("%s", accounts[accountCount].name);
        printf("Enter Initial Balance: ");
        scanf("%f", &accounts[accountCount].balance);
        accounts[accountCount].accountNumber = accountCount + 1;
        accountCount++;
    } else {
        printf("Max accounts reached\n");
    }
}

void displayAccount(int accNo) {
    if(accNo <= accountCount && accNo > 0) {
        printf("Account Number: %d\n", accounts[accNo-1].accountNumber);
        printf("Name: %s\n", accounts[accNo-1].name);
        printf("Balance: %.2f\n", accounts[accNo-1].balance);
    } else {
        printf("Account not found\n");
    }
}

float checkBalance(int accNo) {
    if(accNo <= accountCount && accNo > 0) {
        return accounts[accNo-1].balance;
    } else {
        printf("Account not found\n");
        return -1.0;
    }
}

void deposit(int accNo, float amount) {
    if(accNo <= accountCount && accNo > 0) {
        accounts[accNo-1].balance += amount;
    } else {
        printf("Account not found\n");
    }
}

void withdraw(int accNo, float amount) {
    if(accNo <= accountCount && accNo > 0) {
        if(accounts[accNo-1].balance >= amount) {
            accounts[accNo-1].balance -= amount;
        } else {
            printf("Insufficient funds\n");
        }
    } else {
        printf("Account not found\n");
    }
}

void displayAllAccounts() {
    for(int i = 0; i < accountCount; i++) {
        displayAccount(i+1);
        printf("\n");
    }
}

4. Main Function:

The main function presents a looped menu to the user, offering all the functionalities mentioned above. The user can choose an action, and the corresponding function is called to serve that action. This loop continues until the user chooses to exit.

int main() {
    int choice, accNo;
    float amount;

    while(1) {
        printf("\n1. Create Account\n2. Check Balance\n3. Deposit\n4. Withdraw\n5. Display Account\n6. Display All Accounts\n7. Exit\n");
        printf("Enter choice: ");
        scanf("%d", &choice);

        switch(choice) {
            case 1:
                createAccount();
                break;
            case 2:
                printf("Enter account number: ");
                scanf("%d", &accNo);
                printf("Balance: %.2f\n", checkBalance(accNo));
                break;
            case 3:
                printf("Enter account number: ");
                scanf("%d", &accNo);
                printf("Enter deposit amount: ");
                scanf("%f", &amount);
                deposit(accNo, amount);
                break;
            case 4:
                printf("Enter account number: ");
                scanf("%d", &accNo);
                printf("Enter withdrawal amount: ");
                scanf("%f", &amount);
                withdraw(accNo, amount);
                break;
            case 5:
                printf("Enter account number: ");
                scanf("%d", &accNo);
                displayAccount(accNo);
                break;
            case 6:
                displayAllAccounts();
                break;
            case 7:
                exit(0);
            default:
                printf("Invalid choice\n");
        }
    }

    return 0;
}

  • The program starts by displaying a menu to the user. 
  • Based on the user's choice, the corresponding action is performed. 
  • For actions like deposit, withdraw, and check balance, the user needs to provide an account number. 
  • For deposit and withdraw, apart from the account number, the user also specifies the amount to deposit or withdraw. 
  • After each action, the menu is displayed again, allowing the user to perform more actions or exit the program.
Output:

1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Display Account
6. Display All Accounts
7. Exit
Enter choice: 1
Enter Name: John
Enter Initial Balance: 1000

1. Create Account
...
Enter choice: 2
Enter account number: 1
Balance: 1000.00

1. Create Account
...
Enter choice: 3
Enter account number: 1
Enter deposit amount: 500

1. Create Account
...
Enter choice: 2
Enter account number: 1
Balance: 1500.00

1. Create Account
...
Enter choice: 4
Enter account number: 1
Enter withdrawal amount: 200

1. Create Account
...
Enter choice: 5
Enter account number: 1
Account Number: 1
Name: John
Balance: 1300.00

... (Continues for other choices) ...

Conclusion

The "Banking Management System" in C provides a foundational understanding of how banking operations can be coded and implemented. It covers fundamental programming constructs like data structures, loops, conditionals, and function calls. The project, though basic, can be a stepping stone for beginners, helping them grasp essential C programming concepts. To further enhance this project, one could integrate file operations for persistent data storage, add more features like account transfers, or even implement basic security measures like PIN validation.


Comments