ATM Machine Program in C Language​

An ATM machine program simulates the operations of a real ATM, such as checking account balance, depositing money, withdrawing money, and exiting the program. Below is a detailed implementation of an ATM Machine Program in C Language, along with explanations for each section of the code.

atm_machine_program.c

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

// Function prototypes
void checkBalance(float balance);
float depositMoney(float balance);
float withdrawMoney(float balance);

int main() {
    // Initial balance
    float balance = 1000.00;
    int choice;

    // Menu for the ATM Machine
    do {
        printf("\n===== ATM Machine =====\n");
        printf("1. Check Balance\n");
        printf("2. Deposit Money\n");
        printf("3. Withdraw Money\n");
        printf("4. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                checkBalance(balance);
                break;
            case 2:
                balance = depositMoney(balance);
                break;
            case 3:
                balance = withdrawMoney(balance);
                break;
            case 4:
                printf("Thank you for using the ATM Machine. Goodbye!\n");
                break;
            default:
                printf("Invalid choice! Please try again.\n");
        }
    } while (choice != 4);

    return 0;
}

// Function to check the account balance
void checkBalance(float balance) {
    printf("\nYour current balance is: $%.2f\n", balance);
}

// Function to deposit money into the account
float depositMoney(float balance) {
    float depositAmount;
    printf("\nEnter the amount to deposit: ");
    scanf("%f", &depositAmount);

    if (depositAmount > 0) {
        balance += depositAmount;
        printf("Successfully deposited $%.2f. New balance: $%.2f\n", depositAmount, balance);
    } else {
        printf("Invalid deposit amount. Please try again.\n");
    }

    return balance;
}

// Function to withdraw money from the account
float withdrawMoney(float balance) {
    float withdrawAmount;
    printf("\nEnter the amount to withdraw: ");
    scanf("%f", &withdrawAmount);

    if (withdrawAmount > 0 && withdrawAmount <= balance) {
        balance -= withdrawAmount;
        printf("Successfully withdrew $%.2f. Remaining balance: $%.2f\n", withdrawAmount, balance);
    } else if (withdrawAmount > balance) {
        printf("Insufficient balance! You cannot withdraw more than $%.2f\n", balance);
    } else {
        printf("Invalid withdrawal amount. Please try again.\n");
    }

    return balance;
}

File Tree

[atm_machine_program]/
└── atm_machine_program.c

Leave a Comment