ATM Program in C using if-else
The term "automated teller machine," or ATM, refers to an electro-mechanical device with automated banking platforms that let users complete simple transactions without a teller or branch representative's help. Most ATMs should enable customers to take out cash using a credit or debit card.
ATMs are helpful because they can swiftly execute self-service activities, including cash withdrawals, deposits, bill payments, and account-to-account transfers. Typically, the bank holding the account, the ATM operator, or both will pay fees for cash withdrawals. Some of these costs can be avoided by using an ATM operated right away by the banking institution that manages the account.
The ATM's Operating Principle
To get an ATM to work, you must put plastic ATM cards inside. Certain machines require you to drop your cards, and others require you to swap cards. Your account information and additional security details are stored on the magnetic stripe of these ATM cards. When you drop or swap your card, the computer gets information about your account and requests your PIN. Cash transactions will be allowed by the machines once the authentication is verified.
What is an ATM program in C?
An ATM program can be written in C to represent an ATM transaction. The user of the ATM program must choose an option from those that are shown on the screen. The options include taking money out, putting money in, checking your balance, and leaving.
All we have to do to withdraw the funds is take out the user's withdrawal amount, subtract it from the total amount, and print the message indicating the transaction was successful.
To deposit the money, simply get the user's deposit value, add it to the entire balance, and then print the message indicating the deposit was successful.
We just print the user's total balance to verify the balance.
Program:
#include <stdio.h>
unsigned long cash = 5000, deposit, withdraw;
int pin_no, x, phone_no;
char payment = 'l';
char name[20];
void details() {
printf("RIYA");
printf("\n9876543210");
}
int main() {
while (pin_no != 0000) {
printf("ENTER YOUR SECRET PIN NUMBER:");
scanf("%d", &pin_no);
if (pin_no != 0000)
printf("PLEASE ENTER VALID PASSWORD\n");
}
do {
printf("********Welcome to ATM Service**************\n");
printf("1. User Details\n");
printf("2. Check Balance\n");
printf("3. Withdraw Cash\n");
printf("4. Deposit Cash\n");
printf("5. Quit\n");
printf("******************?**************************?*\n\n");
printf("Enter your option: ");
int option;
scanf("%d", &option );
if (option == 1) {
details();
} else if (option == 2) {
printf("\n YOUR BALANCE IN Rs : %lu ", cash);
} else if (option == 3) {
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 > (cash - 500)) {
printf("\n INSUFFICIENT BALANCE");
} else {
cash = cash - withdraw;
printf("\n\n PLEASE COLLECT CASH");
printf("\n YOUR CURRENT BALANCE IS%lu", cash);
}
} else if (option == 4) {
printf("\n ENTER THE AMOUNT TO DEPOSIT: ");
scanf("%lu", &deposit);
cash = cash + deposit;
printf("YOUR BALANCE IS %lu", cash);
} else if (option== 5) {
printf("\n I APPRECIATE YOU USING THE ATM. ");
x = 1;
} else {
printf("\n WRONG CHOICE ");
}
printf("\n\n\nARE YOU INTERESTED IN FURTHER TRANSACTION? (y/n): \n");
fflush(stdin);
scanf(" %c", &payment);
if (payment == 'n' || payment == 'N')
x = 1;
} while (!x);
printf("\n\n WE APPRECIATE YOU USING OUR ATM. ");
return 0;
}
This C program asks users to enter a PIN while simulating an ATM service. It provides balance checking, withdrawal, deposit, and user information display functions. If-else statements are used for transaction handling and menu navigation, and the program continues to run until the user decides to stop it.
Output:
How does this program work?
- The three logical procedures the ATM program adheres to are checking balance, depositing money, and withdrawing cash.
- The if else in C with conditions is used to run these three program sections. Accurate information is provided by the results only if all requirements are satisfied.
- For instance, when using the ATM program in C, only the withdrawal process will begin if there is enough money in the bank account; if not, you can proceed with another transaction or use the options to check your balance.
The ATM program will also display the updated account balance when a user deposits money after executing the code portion. The third method allows the user to check their account balance whenever they withdraw or deposit using an ATM.