Hello, I need some help with the program included below.
Code:
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* Declare Variables */
/* ----------------- */
int x, number_of_deposits, number_of_withdrawals;
float deposits[50], withdrawals[50];
float current_balance;
float balance;
float total_deposits = 0, total_withdrawals = 0;
char first_name[20];
/* Output initial greeting */
/* ------------------------*/
printf("Welcome to the Sears Banking System.\n\n");
printf ("Please enter your first name: ");
scanf ("%s", first_name);
fflush(stdin);
printf("\nHello, %s.\n\n", first_name);
/* Prompt user for current balance in dollars and cents. */
/* ----------------------------------------------------- */
do
{
printf ("Please enter your current balance in dollars and cents: ");
scanf ("%f",¤t_balance);
fflush(stdin);
if (current_balance < 0)
printf ("Error: Beginning balance must be at least zero, please re-enter!\n\n");
} while (current_balance < 0); /* end do-while loop */
/* Prompt user for the number of withdrawals */
/* ----------------------------------------- */
do
{
printf ("\nEnter the number of withdrawals: ");
scanf ("%i",&number_of_withdrawals);
fflush (stdin);
if (number_of_withdrawals < 0 || number_of_withdrawals > 50)
printf ("Error: Number of withdrawals must be between zero and 50, please re-enter!\n\n");
} while (number_of_withdrawals < 0 || number_of_withdrawals > 50); /* end do-while trap loop */
/* Prompt user to enter the number of deposits. */
/* -------------------------------------------- */
do
{
printf ("\nEnter the number of deposits: ");
scanf ("%i",&number_of_deposits);
fflush (stdin);
if ( number_of_deposits < 0 || number_of_deposits > 50)
printf ("Error: Number of deposits must be between 0 and 50, please re-enter!\n\n");
} while (number_of_deposits < 0 || number_of_deposits > 50); /* end do-while trap loop */
printf("\n");
/* Prompt user for positive deposits and withdrawals. */
/* -------------------------------------------------- */
for (x = 1; x <= number_of_deposits; x++)
{
do
{
printf ("Enter the amount of deposit #%i: ", x);
scanf ("%f",&deposits[x]);
fflush (stdin);
if (deposits[x] <= 0)
printf ("*** Deposit amount must be greater than zero. Please re-enter! ***\n");
} while (deposits[x] <= 0);
total_deposits = total_deposits + deposits[x];
}// end for loop
printf("\n");
for (x = 1; x <= number_of_withdrawals; x++)
{
do
{
printf ("Enter the amount of withdrawal #%i: ", x);
scanf ("%f",&withdrawals[x]);
fflush (stdin);
if (withdrawals[x] > current_balance)
printf ("***Withdrawal amount exceeds current balance.***\n");
else
if (withdrawals[x] <= 0)
printf ("*** Withdrawal amout must be greater than zero. Please re-enter! ***");
} while (withdrawals[x] > current_balance || withdrawals[x] <= 0); /* end do-while loop */
total_withdrawals = total_withdrawals + withdrawals[x];
/* If balance goes to zero, reset the withdrawal count */
/* -------------------------------------------------- */
balance = current_balance - total_withdrawals + total_deposits;
if (balance == 0)
{
printf ("\n *** Balance is now zero. No more withdrawals can be made at this time. ***\n");
number_of_withdrawals = x;
break;
} // end-if
} //end for loop
/* Calculate and display the closing balance */
/* ---------------------------------------- */
printf ("\n*** Your closing balance is $%.2f, %s*** \n", balance, first_name);
if (balance >= 5000.00)
printf ("*** Time to invest some money!*** \n\n");
else if (balance >= 15000.00 && balance <= 49999.99)
printf ("*** Maybe you should consider a CD.*** \n\n");
else if (balance >= 1000.00 && balance <= 14999.99)
printf ("*** Keep up the good work.*** \n\n");
else
printf ("*** %s, your balance is getting low!*** \n\n", first_name);
/* Display bank record */
/* ------------------ */
printf (" *** Bank Record ***\n");
printf ("\nStarting Balance:$ %13.2f\n\n", current_balance);
for (x = 1; x <= number_of_deposits; x++)
{
printf ("Deposit #%i: %13.2f\n", x, deposits[x]);
}
for (x = 1; x <= number_of_withdrawals; x++)
{
printf ("\nWithdrawal #%i: %13.2f", x, withdrawals[x]);
}
printf ("\n\nEnding Balance is:$ %13.2f\n", balance);
{
getch();
return 0;
}
} /*end main*/
I need to alter this program so that it uses at least three "non-trivial" functions (non-trivial meaning that it does more than just print a line of text). My problem is that the text book I am using isn't very helpful so any help would be much appreciated.
Thanks