Index
Bank ATM System
Here we create a Bank ATM System in C Language which is used for checking balance, depositing money, withdrawing money, and transferring funds between accounts.
ATM Operations Formula
- Balance Check :- Simply displays the current balance of an account.
- Deposit: – Increases the balance of an account by the deposited amount.
- Withdrawal:- Decreases the balance of an account by the withdrawn amount if the balance is sufficient.
- Transfer: – Decreases the balance of an account and increases the balance of another account by the transferred amount if the source account has sufficient funds.
Project Codes
Here is the complete project codes,
#include <stdio.h> #include <stdbool.h> // Structure to represent an account typedef struct { int accountNumber; float balance; } Account; // Function to check balance void checkBalance(Account *account) { printf("Account Balance: $%.2f\n", account->balance); } // Function to deposit money void deposit(Account *account, float amount) { if (amount > 0) { account->balance += amount; printf("$%.2f deposited successfully.\n", amount); } else { printf("Invalid deposit amount.\n"); } } // Function to withdraw money void withdraw(Account *account, float amount) { if (amount > 0 && amount <= account->balance) { account->balance -= amount; printf("$%.2f withdrawn successfully.\n", amount); } else { printf("Insufficient balance or invalid withdrawal amount.\n"); } } // Function to transfer funds between accounts void transfer(Account *sourceAccount, Account *destinationAccount, float amount) { if (amount > 0 && amount <= sourceAccount->balance) { sourceAccount->balance -= amount; destinationAccount->balance += amount; printf("$%.2f transferred successfully from Account %d to Account %d.\n", amount, sourceAccount->accountNumber, destinationAccount->accountNumber); } else { printf("Insufficient balance or invalid transfer amount.\n"); } } int main() { // Initialize two accounts Account account1 = {123456, 1000.0}; Account account2 = {654321, 2000.0}; int choice; float amount; printf("Welcome to the ATM Simulation!\n"); do { printf("\nATM Menu:\n"); printf("1. Check Balance\n"); printf("2. Deposit\n"); printf("3. Withdraw\n"); printf("4. Transfer Funds\n"); printf("5. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Account 1:\n"); checkBalance(&account1); printf("Account 2:\n"); checkBalance(&account2); break; case 2: printf("Enter amount to deposit: $"); scanf("%f", &amount); deposit(&account1, amount); break; case 3: printf("Enter amount to withdraw: $"); scanf("%f", &amount); withdraw(&account1, amount); break; case 4: printf("Enter amount to transfer: $"); scanf("%f", &amount); transfer(&account1, &account2, amount); break; case 5: printf("Exiting program.\n"); break; default: printf("Invalid choice. Please try again.\n"); } } while (choice != 5); return 0; }