This works, within the limitations of the accuracy of floats, which can't represent all dollars and cents, accurately.
Code:
#include <stdio.h>
#define SENTINEL 0
float endbal, finbal, outdep, withdraw;
int main (void)
{
printf("BANK RECONCILIATION FOR: 10/21/98");
printf("\n\nEnding balance on statement:");
scanf ("%f", &endbal);
printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
scanf ("%f", &outdep);
while (outdep!= SENTINEL)
{
finbal = finbal + outdep;
printf("Enter outstanding dep (%d to quit)>", SENTINEL);
scanf("%f", &outdep);
}
printf("Outstanding check/withdrawal (or %d to quit)>", SENTINEL);
scanf ("%f", &withdraw);
while (withdraw!=SENTINEL)
{
finbal = finbal - withdraw;
printf("Enter withdrawal (%d to quit)>", SENTINEL);
scanf("%f", &withdraw);
}
/* the outstanding deposits and withdrawals, are already sub-totaled
into finbal. So this is all you need:
*/
finbal = finbal + endbal;
printf("Your final balance in your checkbook should be $ %f\n" , finbal);
return 0;
}
If you need more accuracy, you can either:
1) "normalize" the errors out of the float values
or
2) throw away the float data types, and use int's for dollars, and int's for cents.