Newest update to code
Code:
#include <stdio.h>
void print_comment ( current_balance, first_name) //to print comment based on amount
{
printf ("*** The closing balance is $%.2f ***\n", current_balance);
if (current_balance >= 50000.00 )
printf ("***%s, Time to invest some money! ***", first_name);
else
if (current_balance >= 15000.00 )
printf ("***%s, Maybe you should consider a CD. ***", first_name);
else
if (current_balance >= 1000.00 )
printf ("***%s, Keep up the good work. ***", first_name);
else
printf ("***%s, Your balance is very low. ***", first_name);
}// end function
void main (void)
{
/* Variable Declarations */
/* --------------------- */
char first_name[20];
int num_of_deposits, num_of_withdrawals, i;
float deposit_amount[50], withdraw_amount[50];
float start_balance, current_balance;
/*Prompt user to input their name*/
/*-------------------------------*/
printf ("What is your name? ");
scanf ("%s", first_name);
fflush(stdin);
/* Greet user with his/her name and title of program */
/*---------------------------------------------------*/
printf ("\nHi %s. Welcome to Colleen's Banking program!\n", first_name);
printf ("\n"); // spacing
/* Prompt user for starting balance */
/* -------------------------------- */
do
{
printf ("Enter current balance in dollars and cents: ");
scanf ("%f", &start_balance);
fflush(stdin);
if (start_balance < 0)
printf("Error: Starting Balance must be at least zero! Please re-enter!\n\n");
} while (start_balance < 0);
/* Prompt for the number of withdrawals */
/* -------------------------------------------------------- */
do
{
printf ("\nEnter the number of withdrawals (0-50): ");
scanf ("%i", &num_of_withdrawals);
fflush(stdin);
/* Emsure that user did not enter less than 0 withdrawals */
/* Ensure that user did not enter more than 50 withdrawals. */
/*----------------------------------------------------------*/
if (num_of_withdrawals > 50)
printf ("*** Maximum amount of withdrawals is 50. Please re-enter!***\n");
if (num_of_withdrawals < 0)
printf ("*** Negative number of withdrawals not allowed. ***\n");
} while (num_of_withdrawals > 50 || num_of_withdrawals < 0);
/* Prompt for the number of deposits. */
/* ----------------------------------------------------- */
do
{
printf ("\n\nEnter the number of deposits (0-50): ");
scanf ("%i", &num_of_deposits);
fflush(stdin);
/* Ensure that user did not enter less than 0 deposits. */
/* Ensure that user did not enter more than 50 deposits. */
/*-------------------------------------------------------*/
if (num_of_deposits > 50)
printf ("*** Maximum amount of deposits is 50. Please re-enter! ***\n");
if (num_of_deposits < 0)
printf ("*** Negative number of deposits not allowed. ***\n");
} while ( num_of_deposits > 50 || num_of_deposits < 0);
/* Retain starting balance for bank record. */
/* ---------------------------------------- */
current_balance = start_balance;
/* Prompt for all deposit amounts, keeping track of current balance. */
/* ---------------------------------------------------------------- */
printf ("\n"); // spacing
for (i = 0; i < num_of_deposits; i++ )
{
do
{
printf ("Enter the amount of deposit #%i: ", i+1 );
scanf ("%f", &deposit_amount[i]);
fflush(stdin);
if (deposit_amount[i] <= 0)
printf ("*** Deposit amount must be positive! Please re-enter ***\n");
} while (deposit_amount[i] <= 0);
current_balance = current_balance + deposit_amount[i];
} // end for loop
/* Prompt for all withdrawal amounts, keeping track of current balance. */
/* ------------------------------------------------------------------- */
printf ("\n"); // spacing
for (i = 0; i < num_of_withdrawals; i++ )
{
/* Enter amounts, and be sure amount does not exceed current balance. */
/* ------------------------------------------------------------------ */
do
{
printf ("Enter the amount of withdrawal #%i: ", i+1 );
scanf ("%f", &withdraw_amount[i]);
fflush(stdin);
if (withdraw_amount[i] > current_balance)
printf ("*** Withdrawal amount exceeds current balance. ***\n");
else
if (withdraw_amount[i] <= 0)
printf ("*** Withdrawal amount must be greater than zero! ***\n");
} while (withdraw_amount[i] > current_balance || withdraw_amount[i] <= 0);
current_balance = current_balance - withdraw_amount[i];
/* If Balance goes to zero, no more withdrawals allowed */
if(current_balance == 0)
{
printf ("\n*** Balance is now zero. No more withdrawals allowed! ***\n");
num_of_withdrawals = i + 1;
break;
} // end-if
} // end for loop.
{
print_comment(current_balance, first_name);
}
/* Output bank record: Starting balance, deposits, withdrawals and end balance. */
/* -------------------------------------------------------------------------- */
printf ("\n\n");
printf ("*** Bank Record ***\n");
printf ("Starting Balance: $%13.2f\n\n", start_balance);
for (i = 0; i < num_of_deposits; i++ )
printf ("Deposit #%2i: %15.2f\n", i+1, deposit_amount[i]);
if (num_of_deposits > 0)
printf ("\n"); // spacing
for (i = 0; i < num_of_withdrawals; ++i )
printf ("Withdrawal #%2i: %15.2f\n", i+1, withdraw_amount[i]);
printf ("\nEnding Balance: $%15.2f\n\n", current_balance);
} // end main.