1) An overview of what your program does.
The entire program asks the user for a starting balance, then deposits and withdrawals, then asks the amounts of each, and then prints a record of all transactions and an ending balance.
The area i'm having difficulty with is the part where the user enters the amount of deposits.
in main it calls my function deposits() which looks like:
int deposits ()
{
int number_of_deposits;
do
{
printf ("\n\nEnter the number of deposits: ");
scanf ("%i", &number_of_deposits);
fflush(stdin);
if (number_of_deposits > 50)
printf ("*** Too many deposits. ***\n");
if (number_of_deposits < 0)
printf ("*** Negative number of deposits not allowed. ***\n");
} while ( number_of_deposits > 50 || number_of_deposits < 0);
return number_of_deposits;
}
then it asks the user for the amount of the deposits:
for (i = 0; i < number_of_deposits; i++ )
{
do
{
printf ("Enter the amount of Deposit #%i: ", i+1 );
scanf ("%f", &amount_to_deposit[i]);
fflush(stdin);
if (amount_to_deposit[i] <= 0)
printf ("*** Deposit amount must be positive, please re-enter ***\n");
} while (amount_to_deposit[i] <= 0);
current_balance = current_balance + amount_to_deposit[i];
} /* end for loop */
2) The result of your current code.
The for loop that asks the user for amount of each deposit just keeps looping forever.
for some reason the "number_of_deposits" in my for loop isn't the same as the number the user entered when the function was called.
3) What you expected your code to do.
As you can see I want the number that the user enters when the "deposits" function is called to be stored in the variable "number_of_deposits" so that my for loop will actually exit.
I've tried rewriting my function a number of different ways but the result seems to be the same.