Q:

C program to perform the ATM Transactions

0

C program to perform the ATM Transactions

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here, we will implement an ATM transactions program that will perform the operations like check the balance, withdraw the amount, and deposit the amount to the bank.

Program:

The source code to perform the ATM Transactions is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to perform the
// ATM Transactions

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

int pin = 0;

void readPin()
{
    while (1) {
        printf("Enter PIN: ");
        scanf("%d", &pin);

        if (pin == 1234)
            break;
        printf("Please enter valid PIN number\n");
    }
}

int main()
{
    int option = 0;

    char flag = 'y';

    unsigned long amount = 15000;
    unsigned long deposit = 0;
    unsigned long withdraw = 0;

    readPin();

    do {
        printf("\n\n********Welcome to ATM Service**************\n");
        printf("\t1. Balance Enquiry\n");
        printf("\t2. Cash Withdrawal\n");
        printf("\t3. Deposit Amount\n");
        printf("\t4. Exit\n");
        printf("******************?**************************?*\n\n");

        printf("Enter your choice: ");
        scanf("%d", &option);

        switch (option) {
        case 1:
            printf("\nYour current balance is: %lu rs", amount);
            break;

        case 2:
            printf("\nEnter Amount: ");
            scanf("%lu", &withdraw);

            if (withdraw % 100 != 0) {
                printf("\nEnter amount in muliple of 100");
            }
            else if (withdraw > amount) {
                printf("\nInsufficent balance");
            }
            else {
                amount = amount - withdraw;
                printf("\n\nPlease collect your cash");
                printf("\nYour current balance is: %lu", amount);
            }
            break;

        case 3:
            printf("\nEnter amount to deposit: ");
            scanf("%lu", &deposit);

            amount = amount + deposit;

            printf("Your balance is: %lu", amount);
            break;

        case 4:
            printf("\nThank you for using ATM");
            exit(0);
            break;

        default:
            printf("\nSelect correct option");
        }
    } while (1);

    return 0;
}

Output:

Enter PIN: 1234


********Welcome to ATM Service**************
        1. Balance Enquiry
        2. Cash Withdrawal
        3. Deposit Amount
        4. Exit
******************?**************************?*

Enter your choice: 3

Enter amount to deposit: 15000
Your balance is: 30000

********Welcome to ATM Service**************
        1. Balance Enquiry
        2. Cash Withdrawal
        3. Deposit Amount
        4. Exit
******************?**************************?*

Enter your choice: 1

Your current balance is: 30000 rs

********Welcome to ATM Service**************
        1. Balance Enquiry
        2. Cash Withdrawal
        3. Deposit Amount
        4. Exit
******************?**************************?*

Enter your choice: 4

Thank you for using ATM

Explanation:

Here, we implemented ATM transactions, a menu to perform banking transactions like balance enquiry, withdrawal, deposit. First of all, we validated the PIN to perform ATM transactions. Then we provide the options to select and perform operations accordingly and printed the result on the screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to read the height of a person and the p... >>
<< C program to extract the last two digits from a gi...