I am working on writing a program for my C programming class in which we have to make a basic program that can balance a checkbook. It prompts the user for a starting balance, can add and subtract amounts, and should deduct a $10 fee if the user overdrafts. The code I have so far is giving me some trouble.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
float bal, creditDebit, newBalance ;
printf("This is your checkbook balancing utility.\n");
printf("You will enter your current balance followed by\n");
printf("checkbook entries. Use + and - to indicate deposits\n");
printf("and withdrawals. Signal the end of processing by\n");
printf("entering a '0'\n");
printf(">>>Please enter your initial balance: ");
scanf("%f", &newBalance);
while(creditDebit != 0) {
printf("\n");
printf("Enter deposit (+) or Withdrawl (-): ");
scanf("%f", &creditDebit);
bal += creditDebit;
if (bal < 0) {
printf("***I am sorry, you have bounced this check. $10 will be "
"deducted\n");
bal -= 10;
}
printf("Current balance: %.2f\n", bal);
}
system("pause");
exit(0);
}
It takes the initial balance and will let me input a credit or a debit but the part where it is supposed to display a new balance after each deposit is where I am getting some trouble.