My issue after first iteration let's assume available balance is $1000 and user adds $100 to it and then after continuing with the option then user reaches a stage with the option "Do you want to continue" and if user hits 'yes' then it takes user back to same loop but the balance now shows $1000 not $1100.How to go about it?Thanks
Code:
include
int last()
{
int choice;
printf("\n do u want to continue:\n 1>yes \n 2>No\n");
scanf("%d",&choice);
if(choice==1)
{
return main();
}
else
{
printf("\n thank you have a great day!!!!!");
}
}
int hello()
{
int b=1000,w,d,p;
char ch,choice;
printf("\n enter your choice:\n 1.Balance \n 2.Deposist \n 3.Withdraw\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n the balance is %d\n",b);
return last();
break;
case 2:
printf("\n enter the amount to be deposisted:\n");
scanf("%d",&d);
d=d+b;
printf("\n present balance is %d",d);
return last();
break;
case 3:
printf("\n enter the amount to be withdrawn\n");
scanf("%d",&w);
if(w>b)
{
printf("\n amount is too big\n");
return hello();
}
else
{
w=b-w;
printf("\n present balance is %d\n",w);
}
return last();
break;
}
}
int main()
{
int p;
printf("Welcome to ATM:\n");
printf("Enter the 4 digit pin please:\n");
scanf("%d",&p);
if(p==2133)
{
return hello();
}
else
{
return main();
}
}
Top comments (0)