ATM Machine Program Source Code
#include <stdio.h>unsigned long int amount = 50000, depositS;
//Number Of Notes Available in The ATM Machine, down below statements
unsigned long int FiveThousandNotes = 50;
unsigned long int ThousandNotes = 50;
unsigned long int FiveHundredNotes = 50;
unsigned long int OneHundredNotes = 50;
unsigned long int TenNotes = 50;
unsigned long int fiftyNotes = 50;
unsigned long int withdrawAmount;
unsigned long int totalMoney;
unsigned long int fivethousand = 0, thousand = 0, fiveHundred =
0, oneHundred = 0, fifty = 0, ten = 0;
int choice, pin, k;
char transaction = 'y';
main ()
{
while (pin != 1520)
{
printf ("ENTER YOUR FOUR DIGIT PIN NUM:"); //User will Enter His Four Digit Pin Code
scanf ("%d", &pin); // REads OutPut
if (pin != 1520) /// IF It is Not The COrrect Pin
printf ("WRONG PASSWORD! TRY AGAIN\n");
}
do // It Will Once Print All the Statements Given Below
{
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: "); // Chooes One of The Option
scanf ("%d", &choice); //Read The input
switch (choice)
{
case 1: // Check Balance
printf ("\n YOUR BALANCE IN Rs : %lu ", amount);
break;
case 2: // To widthdraw Money
printf ("Enter the amount in multiple of 10:"); // Enter money more than 100 in multiples
scanf ("%lu", &withdrawAmount);
if (withdrawAmount < amount)
{
amount = amount - withdrawAmount;
printf ("\nYour balance is Rs: %lu \n", amount);
}
if (withdrawAmount % 10 != 0) // If not in Multip
{
printf ("Invalid amount\n");
return 0;
}
totalMoney =
ThousandNotes * 1000 + FiveHundredNotes * 500 +
OneHundredNotes * 100 + fiftyNotes * 50 + TenNotes * 10;
if (withdrawAmount > totalMoney)
{
printf ("Sorry,Insufficient money\n");
return 0;
}
fivethousand = withdrawAmount / 5000;
if (fivethousand > FiveThousandNotes)
fivethousand = FiveThousandNotes;
withdrawAmount = withdrawAmount - fivethousand * 5000;
thousand = withdrawAmount / 1000;
if (thousand > ThousandNotes)
thousand = ThousandNotes;
withdrawAmount = withdrawAmount - thousand * 1000;
fiveHundred = withdrawAmount / 500;
if (fiveHundred > FiveHundredNotes)
fiveHundred = FiveHundredNotes;
withdrawAmount = withdrawAmount - fiveHundred * 500;
if (withdrawAmount > 0)
oneHundred=withdrawAmount/100;
if (oneHundred > OneHundredNotes)
oneHundred = OneHundredNotes;
withdrawAmount = withdrawAmount - oneHundred * 100;
if (withdrawAmount > 0)
fifty=withdrawAmount/50;
if (fifty > fiftyNotes)
fifty = fiftyNotes;
withdrawAmount = withdrawAmount - fifty * 50;
if (withdrawAmount > 0)
ten = withdrawAmount / 10;
if (ten > TenNotes)
ten = TenNotes;
withdrawAmount = withdrawAmount - ten * 10;
printf ("Total 5000 note:%lu\n", fivethousand);
printf ("Total 1000 note:%lu\n", thousand);
printf ("Total 500 note:%lu\n", fiveHundred);
printf ("Total 100 note:%lu\n", oneHundred);
printf ("Total 50 notes:%lu\n", fifty);
printf ("Total 10 notes:%lu\n", ten);
break;
case 3:
printf ("\n ENTER THE AMOUNT TO DEPOSIT:");
scanf ("%lu", &depositS);
amount = amount + depositS;
printf ("YOUR BALANCE IS %lu", amount);
break;
case 4:
printf ("\n THANK U USING ATM");
break;
default:
printf ("\n INVALID CHOICE");
}
printf ("\n\n\n DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): \n");
fflush (stdin); //It make a wide Space Between the Line
scanf ("%c", &transaction);
if (transaction == 'n' || transaction == 'N')
k = 1;
}
while (!k);
printf ("\n\n THANKS FOR USING OUT ATM SERVICE");
return 0;
}
Outputs
I hope that this ATM Program In C language has helped you to understand how ATM Machine works.
can you explain to me how this atm program works ? i hope that you can help me with this :)
ReplyDelete