I have to make a program for class to maintain a bank balance. The problem I am having is I can make all my deposits then my withdrawals, but i cant return to deposit after i make a withdrawal. How can I make it with only one while loop so i can switch between the two without any problems?
Code:
int main()
{
double total = 0.0;
double x;
char resp;
explanation();
printf("BANK ACCOUNT PROGRAM\n");
printf("--------------------\n\n");
printf("Please Enter the old balance: ");
scanf("%lf%*c",&total);
printf("Enter the transactions now.\n");
printf("Enter an \"F\" for the transaction type when you are finished.\n\n");
printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
scanf("%c%*c",&resp);
while(resp=='D')
{
printf("Amount: ");
scanf("%lf%*c",&x);
total = total + x;
printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
scanf("%c%*c",&resp);
}
while(resp=='W')
{
printf("Amount: ");
scanf("%lf%*c",&x);
total = total - x;
printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
scanf("%c%*c",&resp);
}
while(resp=='F')
{
printf("Your ending balance is: $%8.2lf\n",total);
printf("Program Ending");
}
}