Hi guys, I'm fairly new to C as well as programming in general, this is a basic banking program I am working on. It prompts the user to enter name, withdrawal, & deposit amounts then calculates all and gives us the final balance. Well unfortunately its not quite working as it should its basically not calculating the amounts correctly. I have a feeling its due to my loop structure. I just cant figure out what is wrong in there. So any input on this would be helpful.
Code:#include <stdio.h> int main (void) { int deposit_process, withDrl, x; float deposit[50], withDrawal[50]; float baLance, Sb, Total; char Name[20]; printf ("Welcome to the Sears Banking System\n\n"); printf ("\nPlease enter your first name: ", Name); scanf ("%s", Name); fflush (stdin); /*----------------------------------*/ /*Prompt user for balance-----------*/ do { printf ("\nHello %s\n\n", Name); printf ("%s, please enter your current balance in dollars and cents: ", Name); scanf ("%f", &Sb); fflush (stdin); if (Sb <= 0) printf ("Error: beginning balance must be at least zero, please re-enter.\n"); } while (Sb <= 0); /*--------------------------------*/ /*prompt user for # of withdrawals*/ do { printf ("\nEnter the number of withdrawals: "); scanf ("%i", &withDrl); fflush (stdin); if (withDrl <= 0) printf ("Error: please re-enter.\n"); } while (withDrl <= 0); /*----------------------------------------*/ /*Prompt user for # of deposits-------------------*/ do { printf ("\nEnter the number of deposits: "); scanf ("%i", &deposit_process); fflush (stdin); if (deposit_process <= 0) printf ("Error: Number of deposits must be at least zero, please re-enter\n"); }while (deposit_process <= 0); /*---------------------------------*/ /*-depostit loop-------------------*/ for (x = 1; x <= deposit_process; x++){ do { printf ("\nEnter the amount of deposit #%i: ", x); scanf ("%f",&deposit[x]); fflush (stdin); if (deposit[x] > 0) deposit[x] = deposit[x] + baLance; else printf("***Deposit amount must be greater than zero. Please re-enter!***\n"); }while (deposit_process <= 0); baLance = Sb + deposit[x]; } //*-------------------------*// //*--withdrawal loop---*// for (x = 1; x <= withDrl; x++) { do { printf("\nEnter the amount of withdrawal #%i: ", x); scanf ("%f", &withDrawal[x]); fflush(stdin); if (withDrawal[x] <= 0) printf ("***Error: Number of withdrawals must be greater than 0.***"); if (withDrawal[x] <= baLance) baLance = baLance - withDrawal[x]; else printf ("***Withdrawal amount exceeds current balance, please re-enter.***\n"); }while (withDrawal[x] <= 0); Total = baLance - withDrawal[x]; } /*----------------------------------*/ /*------closing balance output--------*/ printf("\n***The closing balance %s is $%f***\n", Name, Total); if (Total >= 50000) printf("\n***%s it is time to invest some money***", Name); if (Total >= 15000) printf("\n***%s maybe you should consider a CD.***\n", Name); else if (Total >= 1000) printf ("\n***%s keep up the good work!***", Name); else printf ("\n***%s your balance is getting low!***\n", Name); /*------------------------------------------------------------*/ /*---------------Bank printout--------------------------------*/ printf ("\n ***Bank Record***\n"); printf ("\nStarting Balance: $ %f\n", Sb); for (x = 1; x <= deposit[x]; x++ ) printf ("\nDeposit #%i: %f\n", x, deposit[x]); for (x = 1; x <= withDrawal[x]; x++) printf ("\nWithdrawal #%i: %f\n", x, withDrawal[x]); printf ("\nEnding Balance:$ %f\n", Total); return 0; }/*----end of program------*/



LinkBack URL
About LinkBacks




