ATM Service: Check Balance, Withdraw Cash, Deposit Cash, Quit – C Program

This program is a basic ATM simulator that allows the user to check their balance, withdraw cash, deposit cash, and quit. The user is required to enter their PIN number to access the ATM. If the user enters an incorrect PIN number, they will be prompted to enter a valid one. Once the user has accessed the ATM, they will be presented with a menu of options.

The first option allows the user to check their account balance. The second option allows the user to withdraw cash. If the amount entered is not a multiple of 100, an error message will be displayed. If the amount entered is greater than the available balance minus 500, an error message will be displayed. Otherwise, the user will be able to withdraw the requested amount, and their account balance will be updated accordingly.

The third option allows the user to deposit cash into their account. The user will be prompted to enter the amount they wish to deposit, and their account balance will be updated accordingly.

The fourth option allows the user to quit the ATM simulator.

After each transaction, the user will be asked if they wish to perform another transaction. If the user enters ‘y’ or ‘Y’, they will be able to perform another transaction. Otherwise, the program will terminate.

black laptop computer turned on showing computer codes
Photo by Markus Spiske on Pexels.com

The program is written in C programming language and can be compiled and executed using a C compiler.

#include <stdio.h>

int main() {
    unsigned long amount = 1000, deposit, withdraw;
    int choice, pin = 0, k = 0;
    char transaction = 'y';

    while (pin != 1520) {
        printf("ENTER YOUR SECRET PIN NUMBER:");
        scanf("%d", &pin);
        if (pin != 1520) {
            printf("PLEASE ENTER VALID PASSWORD\n");
        }
    }

    do {
        printf("********Welcome to ATM Service**************\n");
        printf("1. Check Balance\n");
        printf("2. Withdraw Cash\n");
        printf("3. Deposit Cash\n");
        printf("4. Quit\n");
        printf("******************?**************************?*\n\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                printf("\n YOUR BALANCE IN Rs : %lu ", amount);
                break;
            case 2:
                printf("\n ENTER THE AMOUNT TO WITHDRAW: ");
                scanf("%lu", &withdraw);
                if (withdraw % 100 != 0) {
                    printf("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
                } else if (withdraw > (amount - 500)) {
                    printf("\n INSUFFICIENT BALANCE");
                } else {
                    amount -= withdraw;
                    printf("\n\n PLEASE COLLECT CASH");
                    printf("\n YOUR CURRENT BALANCE IS: %lu", amount);
                }
                break;
            case 3:
                printf("\n ENTER THE AMOUNT TO DEPOSIT: ");
                scanf("%lu", &deposit);
                amount += deposit;
                printf("YOUR BALANCE IS %lu", amount);
                break;
            case 4:
                printf("\n THANK YOU FOR USING ATM");
                k = 1;
                break;
            default:
                printf("\n INVALID CHOICE");
                break;
        }

        printf("\n\n\n DO YOU WISH TO HAVE ANOTHER TRANSACTION? (y/n): ");
        fflush(stdin);
        scanf(" %c", &transaction);

        if (transaction == 'n' || transaction == 'N') {
            k = 1;
        }
    } while (!k);

    printf("\n\n THANKS FOR USING OUR ATM SERVICE");
    return 0;
}

Leave a Reply