#include <stdio.h>
float promptInitialBalance(void);
int promptIntendedNumDeposits(void);
int promptIntendedNumWithdrawals(void);
float promptDeposits(float balance,int numDeposits, float depositRecords[5]);
float promptWithdrawals(float balance, int numWithdrawals, float withdrawalRecords[5]);
void printClosingBalanceSummary(float balance);
void printBankRecord(float balance_0, float balance, int numDeposits, int numWithdrawals, float depositRecords[5], float withdrawalRecords[5]);
int main(void)
{
float balance_0 = 0.0;
float balance = 0.0;
int numDeposits=0;
int numWithdrawals=0;
float depositRecords[5];
float withdrawalRecords[5];
printf("Welcome to the Computer Banking System\n");
balance_0 = promptInitialBalance();
balance = balance_0;
numDeposits = promptInitialBalance();
numWithdrawals = promptIntendedNumWithdrawals();
printf("\n");
balance = promptDeposits(balance, numDeposits, depositRecords);
printf("\n");
balance = promptWithdrawals(balance, numWithdrawals, withdrawalRecords);
printClosingBalanceSummary(balance);
printBankRecord(balance_0, balance, numDeposits, numWithdrawals, depositRecords, withdrawalRecords);
return 0;
}
float promptInitialBalance(void)
{
float balance_0 = 0.0;
while (balance_0 < 0.0)
{
printf("\nEnter your current balance in dollars and cents: ");
scanf("%lf", &balance_0);
if (balance_0 >= 0.0)
break;
else
printf("*** Beginning balance must be at least zero, please re-enter.\n");
}
return balance_0;
}
int promptIntendedNumDeposits(void)
{
int numDeposits = 0;
while (numDeposits < 0 || numDeposits > 5)
{
printf("\nEnter the number of deposits (0 - 5): ");
scanf("%d", &numDeposits);
if (numDeposits >= 0 && numDeposits <= 5)
break;
else
printf("*** Invalid number of deposits, please re-enter.\n");
}
return numDeposits;
}
int promptIntendedNumWithdrawals(void)
{
int numWithdrawals = 0;
while (numWithdrawals < 0 || numWithdrawals > 5)
{
printf("\nEnter the number of withdrawals (0 - 5): ");
scanf("%d", &numWithdrawals);
if (numWithdrawals >= 0 && numWithdrawals <= 5)
break;
else
printf("*** Invalid number of withdrawals, please re-enter.\n");
}
return numWithdrawals;
}
float promptDeposits(float balance, int numDeposits, float depositRecords[5])
{
int depositCount = 0;
float depositAmount = 0.0;
while (depositCount < numDeposits)
{
printf("Enter the amount of deposit #%d: ", depositCount + 1);
scanf("%lf", &depositAmount);
if (depositAmount >= 0.0)
{
depositRecords[depositCount] = depositAmount;
balance += depositAmount;
depositCount++;
}
else
printf("*** Deposit amount must be greater than or equal to zero, please try again.\n\n");
}
return balance;
}
float promptWithdrawals(float balance, int numWithdrawals, float withdrawalRecords[5])
{
int withdrawalCount = 0;
float withdrawalAmount = 0.0;
while (withdrawalCount < numWithdrawals)
{
printf("Enter the amount of withdrawal #%d: ", withdrawalCount + 1);
scanf("%lf", &withdrawalAmount);
if (withdrawalAmount >= 0.0)
{
if ((balance - withdrawalAmount) < 0.0)
{
printf("*** Withdrawal amount exceeds current balance.\n\n");
}
else
{
withdrawalRecords[withdrawalCount] = withdrawalAmount;
balance -= withdrawalAmount;
withdrawalCount++;
}
}
else
printf("*** Withdrawal amount must be greater than or equal to zero, please try again.\n\n");
}
return balance;
}
void printClosingBalanceSummary(float balance)
{
printf("\n*** The closing balance is: $%.2f ***\n", balance);
if (balance >= 50000.00)
{
printf("*** It is time to invest some money! ***\n");
}
else if (balance >= 15000.00 && balance <= 49999.9)
{
printf("*** Maybe you should consider a CD. ***\n");
}
else if (balance >= 1000.00 && balance <= 14999.99)
{
printf("*** Keep up the good work! ***\n");
}
else if (balance >= 0.0 && balance <= 999.99)
{
printf("*** Your balance is getting low! ***\n");
}
}
void printBankRecord(float balance_0, float balance, int numDeposits, int numWithdrawals, float depositRecords[5], float withdrawalRecords[5])
{
printf("\n");
printf(" *** Bank Record ***\n\n");
printf("Starting Balance: $ %15.2f\n\n", balance_0);
int i=0;
for (i = 0; i < numDeposits; i++)
{
printf("Deposit #%d: %.2f\n", i + 1, depositRecords[i]);
}
for (i = 0; i < numWithdrawals; i++)
{
printf("Withdrawal #%d: %.2f\n", i + 1, withdrawalRecords[i]);
}
printf("\n");
printf("Ending Balance: $ %.2f\n\n", balance);
}
What I have tried:
It keeps saying that i is only declared once. I'm not sure how to fix this.
thanks.