Hello Guys
I am new to C programming and as a part of an assignment I have made an ATM algorithm in C. Though the compiler shows no errors, the code goes into an infinite loop after the first input.
Please Help.
Here's the code:
#include<stdio.h>
#include<conio.h>
void main(){
float bal=0,dep=0,withd=0;
int n1,n2;
clrscr();
do{
clrscr();
printf("\n\t\t************************\t\t\n");
printf("\t\tWelcome To ATM Services\n");
printf("\t\tSelect Your Choice:\n");
printf( "\t\t1)Deposit Cash\n\t\t2)Withdraw Cash\n\t\t3)Bank Statement\n\t\t4)Fast Cash\n\t\t5)Exit\n");
printf("\t\t***********************\t\t\n");
scanf("%d",&n1);
switch(n1){
case 1: printf("Enter the amount to be deposited\n");
scanf("%f",&dep);
if(dep>0){
bal+=dep;
printf("You have deposited %f cash. Your current account balance is %f\n",dep,bal); }
else printf("Invalid amount entered\n");
printf("Press any key to continue\n");
break;
case 2: printf("Enter the amount to be withdrawn\n");
scanf("%f",&withd);
if(withd<bal && withd>0){
bal-=withd;
printf("You have withdrawn %f cash. Your current account balance is %f\n",withd,bal);}
else printf("Insufficient funds in your account\n");
printf("Press any key to continue\n");
break;
case 3: printf("\t\tYour Current Bank Statement Is:\n");
printf("\t\t Your account balance is %f.\n",bal);
printf("Enter any key to continue");
break;
case 4: printf("\t\tWelcome To FastCash\n");
printf("\t\tSelect an alternative:\n");
printf("\t\t1)Rs100\n\t\t2)Rs500\n\t\t3)Rs1000\n");
scanf("%d",&n2);
switch(n2){
case 1: printf("You have chosen to withdraw Rs100\n");
if(bal>=100){
bal-=100;
printf("You have withdrawn Rs100. Your balance is %f\n",bal);
printf("\t\tPlease Collect Your Cash\n");}
else printf("Insufficient Funds in account");
break;
case 2: printf("You have chosen to withdraw Rs500.\n");
if(bal>=500){
bal-=500;
printf("You have withdrawn Rs500. Your account balance is %f\n",bal);
printf("\t\tPlease Collect Your Cash\n"); }
else printf("insufficient Funds");
break;
case 3: printf("You have chosen to withdraw Rs1000\n");
if(bal>=1000){
bal-=1000;
printf("You have withdrawn Rs1000. Your account balance is %f\n",bal);
printf("\t\tPlease Collect Your Cash");}
else printf("Insufficient Funds");
break;
default: printf("\t\tWrong Choice Entered"); } } }
while(n1!=5) ;
getch(); }