Write an algorithm and its corresponding C program to illustrate an ATM
money withdrawl operation from user’s savings’ account. Note: Assumptions
can be made wherever necessary.
Answers
Answered by
0
#include<stdio.h>
unsigned long AMOUNT=51520,DEPOSIT,WITHDRAW;
int CHOICE,PIN,K,TRY=0;
char TRANSACTION=’Y';
void main()
{
clrscr();
while(PIN!= 4567)
{
printf(“\nENTER YOUR PIN NUMBER :”);
scanf(“%d”,&PIN);
if(PIN!=4567)
{
printf(“\nYOU HAVE ENTERED INVALID PIN NUMBER!!\n”);
TRY++;
if(TRY==3)
{
printf(“\nYOU HAVE EXCEEDED MAXIMUM ATTEMPTS TO ENTER PIN NUMBER!!\n”);
getch();
exit();
}
}
}
do
{
clrscr();
printf(“*****WELCOME TO XYZ BANK*****\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(“\nYOUR BALANCE IS RS.%ld\n”,AMOUNT);
break;
case 2:
printf(“\nENTER THE AMOUNT TO WITHDRAW CASH\n”);
scanf(“%ld”,&WITHDRAW);
if(WITHDRAW%100 != 0)
{
printf(“\nPLEASE ENTER THE AMOUNT IN MULTIPLIES OF 100\n”);
}
else if(WITHDRAW>(AMOUNT-1000))
{
printf(“\nINSUFFICIENT BALANCE\n”);
}
else
{
AMOUNT = AMOUNT-WITHDRAW;
printf(“\nPLEASE COLLECT CASH\n”);
printf(“\nYOUR CURRENT BALANCE IS %ld\n”,AMOUNT);
}
break;
case 3:
printf(“\nENTER THE AMOUNT TO DEPOSIT\n”);
scanf(“%ld”,&DEPOSIT);
AMOUNT = AMOUNT+DEPOSIT;
printf(“\nYOUR CURRENT BALANCE IS %ld\n”,AMOUNT);
case 4:
printf(“\nTHANK YOU FOR USING THIS ATM\n”);
break;
default :
printf(“\nINVALID CHOICE\n”);
}
printf(“\n\nDO YOU WISH TO DO ANOTHER TRANSCACTION?(Y/N): “);
fflush(stdin);
scanf(“%c”,&TRANSACTION);
if(TRANSACTION==’n'||TRANSACTION==’N')
K=1;
else
K=0;
}while(!K);
printf(“\nTHANK YOU FOR USING THIS ATM\n”);
getch();
}
Hope it helps...
unsigned long AMOUNT=51520,DEPOSIT,WITHDRAW;
int CHOICE,PIN,K,TRY=0;
char TRANSACTION=’Y';
void main()
{
clrscr();
while(PIN!= 4567)
{
printf(“\nENTER YOUR PIN NUMBER :”);
scanf(“%d”,&PIN);
if(PIN!=4567)
{
printf(“\nYOU HAVE ENTERED INVALID PIN NUMBER!!\n”);
TRY++;
if(TRY==3)
{
printf(“\nYOU HAVE EXCEEDED MAXIMUM ATTEMPTS TO ENTER PIN NUMBER!!\n”);
getch();
exit();
}
}
}
do
{
clrscr();
printf(“*****WELCOME TO XYZ BANK*****\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(“\nYOUR BALANCE IS RS.%ld\n”,AMOUNT);
break;
case 2:
printf(“\nENTER THE AMOUNT TO WITHDRAW CASH\n”);
scanf(“%ld”,&WITHDRAW);
if(WITHDRAW%100 != 0)
{
printf(“\nPLEASE ENTER THE AMOUNT IN MULTIPLIES OF 100\n”);
}
else if(WITHDRAW>(AMOUNT-1000))
{
printf(“\nINSUFFICIENT BALANCE\n”);
}
else
{
AMOUNT = AMOUNT-WITHDRAW;
printf(“\nPLEASE COLLECT CASH\n”);
printf(“\nYOUR CURRENT BALANCE IS %ld\n”,AMOUNT);
}
break;
case 3:
printf(“\nENTER THE AMOUNT TO DEPOSIT\n”);
scanf(“%ld”,&DEPOSIT);
AMOUNT = AMOUNT+DEPOSIT;
printf(“\nYOUR CURRENT BALANCE IS %ld\n”,AMOUNT);
case 4:
printf(“\nTHANK YOU FOR USING THIS ATM\n”);
break;
default :
printf(“\nINVALID CHOICE\n”);
}
printf(“\n\nDO YOU WISH TO DO ANOTHER TRANSCACTION?(Y/N): “);
fflush(stdin);
scanf(“%c”,&TRANSACTION);
if(TRANSACTION==’n'||TRANSACTION==’N')
K=1;
else
K=0;
}while(!K);
printf(“\nTHANK YOU FOR USING THIS ATM\n”);
getch();
}
Hope it helps...
Similar questions