Hi there,
Kindly see my attached code below. This is already running however, I do have a little problem with the WITHDRAWAL part.
For example:
My current balance is 500 and I withdraw 501. It will tell me at first that I have insufficient funds and would prompt me to enter another amount. However, If I enter 501. It will tell me that I have -1 as my New balance which should't be. What I want is it will keep me prompting an mount either less than or equal to my current balance so that it will not display a negative new balance.
#include <stdio.h>
#include <stdlib.h>
int dep=0,ab=0,wdraw=0;
void acctbal()
{
printf ("\n\n---Account Balance---\n\n");
printf ("\n\nYour Current Balance is: %d\n\n",ab);
}
void deposit ()
{
printf ("\n\n---Deposit---\n\n");
printf ("Enter Amount :");
scanf ("%d",&dep);
ab=ab+dep;
printf ("\n\nAmount deposited: %d",dep);
printf ("\nNew Balance: %d\n\n",ab);
}
void withdraw ()
{
if (ab==0)
{
system("ds");
printf ("\n\nplease be reminded that your current balance is: %d\n", ab);
return;
}
else
{
printf ("\n\n--Withdraw--\n\n");
printf ("Enter Amount :");
scanf ("%d", &wdraw);
}
if (ab>=wdraw)
{
ab=ab-wdraw;
printf ("\n\nAmount withdraw: %d",wdraw);
printf ("\nNew balance: %d\n\n", ab);
}
else
{
printf ("\n\n Insufficient Funds--\n");
printf ("please be reminded that your current balance is: %d\n",ab);
printf ("\n\n---Withdraw---\n\n");
printf ("Enter new amount: ");
scanf ("%d",&wdraw);
ab=ab-wdraw;
printf ("\n\namount withdraw: %d",wdraw);
printf ("\n\nNew balance: %d\n\n",ab);
}
}
void main()
{
int ans;
char oper;
a:
system ("ds");
printf ("\n\nTransactions\n\n");
printf ("D- Deposit\n");
printf ("W- Withdraw\n");
printf ("A- Account Balance\n");
x:
printf ("Enter desired transcation:");
scanf ("%s",&oper);
if (oper=='D'||oper=='d')
deposit();
else if (oper=='W'||oper=='w')
withdraw();
else if (oper=='A'||oper=='a')
acctbal();
else
{
printf("\n\n--Invalid Input---\n");
printf("***PLEASE ENTER A VALID TRANSACTION***\n\n");
goto x;
}
c:
printf ("\ndo you want to continue? Press [1]-for yes [2] for no:");
scanf ("%d", &ans);
if (ans==1)
goto a;
else if (ans==2)
{
printf ("\n---THANK YOU FOR BANKING WITH US---\n\n");
return;
}
else
{
printf ("\n\n---INVALID INPUT---\n\n");
goto c;
}
}