I have this whole program working except for the following:
If the current balance goes to zero, then no more withdrawals should be made and it should output a message " Sorry you have no money to withdraw"
This is the only part I can't figure out how to do. I have been trying for days now. Can someone help? Code is below
Code:
#include <stdio.h>
int main ()
{
/*Variable Declarations*/
/*---------------------*/
int x, withdrawals, deposits;
float deposit[50], withdrawal[50];
float total=0, balance;
/*Declare and initalize accumulators for closing balance*/
/*------------------------------------------------------*/
float sum= 0, count=0;
/*Display opening greeting to user*/
/*--------------------------------*/
printf ("\nWelcome to Colleen's Banking System\n\n");
/*Prompt user to input current balance in dollars and cents*/
/*---------------------------------------------------------*/
do
{
printf ("Enter current balance in dollars and cents: " );
scanf ("%f", &balance);
fflush (stdin); //clear input screen
if (balance < 0 )
printf ("Beginning balance must be at least zero, please re-enter!\n\n");
} while (balance < 0 ); //end do loop
/*Prompt user to input number of withdrawals*/
/*------------------------------------------*/
do
{
printf ("\nEnter the number of withdrawals: " );
scanf ("%d", &withdrawals);
fflush (stdin); //clear input screen
if (withdrawals < 0 )
printf ("Error: Number of withdrawals must be at least zero, please re-enter! \n");
} while (withdrawals < 0 ); //end do loop
/*Prompt user to input the number of deposits*/
/*-------------------------------------------*/
do
{
printf ("\nEnter the number of deposits: " );
scanf ("%d", &deposits);
fflush (stdin); //clear input screen
if (deposits < 0 )
printf ("Error: Number of deposits must be at least zero, please re-enter! \n");
} while (deposits < 0 ); //end do loop
/*Promt user to input each deposit amount*/
/*---------------------------------------*/
for( x = 1; x <= deposits; x++)
{
printf ("Enter the amount of deposit #%i: ", x);
scanf ("%f", &deposit[x]);
fflush (stdin); //clear input screen
/*Output appropriate message if deposit amount is less than zero.*/
/*---------------------------------------------------------------*/
if ( deposit < 0 )
{
printf ("***Invalid entry. Deposit amount must be positive.***\n");
deposit[x] = deposit - deposit;
x--;
}
count = count + deposit[x];
} // end for loop
/*Prompt user to input each withdrawal amount*/
/*----------------------------------------------------*/
for( x = 1; x <= withdrawals; x++)
{
printf ("Enter the amount of withdrawal #%i: ", x);
scanf ("%f", &withdrawal[x]);
fflush (stdin); //clear input screen
/*Output appropriate message if withdrawal amount is not positive.*/
/*----------------------------------------------------------------*/
if ( withdrawal < 0 )
{
printf ("***Withdrawal amount must be positive.***\n");
withdrawal[x] = withdrawal - withdrawal;
x--;
}
/*Output appropriate message if withdrawal exceeds current balance.*/
/*-----------------------------------------------------------------*/
if (withdrawal[x] > balance + deposit[x])
{
printf ("***Withdrawal amount exceeds current balance. Please re-enter!***\n");
withdrawal[x] = withdrawal - withdrawal;
x--;
}
sum = sum + withdrawal[x];
/*If balance goes to zero, no more withdrawals should be made*/
/*-----------------------------------------------------------*/
if (withdrawal[x] = balance + deposit[x])
{
printf ("***Sorry you have no money to withdraw!***\n");
withdrawal[x] = withdrawal - withdrawal;
}
} // end for loop
/*Output closing balance amount to user*/
/*-------------------------------------*/
total = (float) balance + count - sum;
printf ("\n***The closing balance is $%.2f***\n", total);
/*Display short advice for user based upon closing balance*/
/*--------------------------------------------------------*/
if (total >= 500000.00 )
printf ("***Time to invest some money!*** \n");
else
if (total > 15000.00&&total <49999.99 )
printf ("***Maybe you should consider a CD.*** \n");
else
if (total > 1000.00&&total <14999.99 )
printf ("***Keep up the good work.*** \n");
else
if (total >=0.00&&total< 999.99 )
printf ("***Your balance is getting low.***\n");
/*Output a Bank Record for user*/
/*-----------------------------*/
printf ("\n***Bank Record***");
printf ("\nStarting Balance: $ %.2f\n\n", balance);
for (x=1; x <= deposits; x++)
{
printf ("Deposit #%i: %.2f\n", x, deposit[x]);
} //end for loop
for (x=1; x <= withdrawals; x++)
{
printf ("\nWithdrawal #%i: %.2f", x, withdrawal[x]);
} //end for loop
printf ("\n\nEnding Balance: $ %.2f\n", total);
} //end main