I am having an issue. When I run this, it misses going to the beg_balance and goes directly to asking for the nm_deposits. Then, it wont take numbers and I am not sure why
Code:
#include<stdio.h>
main ()
{
//Declare variables
int i, s;
int nm_deposits;
int nm_withdrawals;
float beg_balance;
float end_balance;
float deposit_ttl = 0;
float deposits[5];
float withdrawals[5];
//Begin taking information
int x = 1, y = 1;
char c;
printf("Welcome to the Computer Banking System\n\n");
while (beg_balance <= -1)
{
printf ("Enter your current balance in dollars and cents:");
scanf ("%f", &beg_balance);
if (beg_balance <= -1)
{
printf
("*** Beginning balance must be at least zero, please re-enter. \n\n");
continue;
}
end_balance = end_balance + beg_balance;
}
//Get Number of Deposits
do
{
printf ("\nEnter the number of deposits (0 - 5):");
scanf ("%i", &nm_deposits);
while ((c = getchar () != '\n') && c != EOF);
//Error Check
if (deposits < 0 || deposits > 5)
printf ("*** Invalid number of deposits, please re-enter.\n");
}
while (deposits < 0 || deposits > 5);
do
{
//Get Number of Withdrawals
printf ("\nEnter the number of withdrawals (0 - 5):");
scanf ("%i", &nm_withdrawals);
while ((c = getchar () != '\n') && c != EOF);
//Error Check
if (nm_withdrawals < 0 || nm_withdrawals > 5)
printf ("*** Invalid number of withdrawals, please re-enter.\n");
printf ("\n");
}
while (nm_withdrawals < 0 || nm_withdrawals > 5);
//Get Deposit Amounts
while (x <= nm_deposits)
{
printf ("Enter the amount of deposit #%i:", x);
scanf ("%f", &deposits[x]);
//Error Check
if (deposits[x] < 0)
{
printf
("*** Deposit amount must be greater than zero, please re-enter.\n\n");
}
else if (deposits[x] >= 0)
{
end_balance = end_balance + deposits[x];
x++;
while ((c = getchar () != '\n') && c != EOF);
}
}
printf ("\n");
//Get Withdrawal Amounts
while (y <= withdrawals)
{
printf ("Enter the amount of Withdrawal #%i:", y);
scanf ("%f", withdrawals[y]);
if (withdrawals[y] > end_balance)
{
printf ("*** Withdrawal amount exceeds current balance, please re-enter.\n\n");
}
else if (withdrawals[y] <= end_balance)
{
end_balance = end_balance - withdrawals[y];
y++;
while ((c = getchar () != '\n') && c != EOF);
}
}
printf ("\n*** The closing balance is $%.2f ***\n", end_balance);
if (end_balance >= 50000.00)
printf ("*** It is time to invest some money! ***");
else if (end_balance >= 15000.00 && end_balance <= 49999.99)
printf ("*** Maybe you should consider a CD. ***");
else if (end_balance >= 1000.00 && end_balance <= 14999.99)
printf ("*** Keep up the good work! ***");
else if (end_balance >= 0.00 && end_balance <= 999.99)
printf ("*** Your balance is getting low! ***");
//Final Calulations and financial advice
end_balance = beg_balance + deposit_ttl;
printf ("\n\nThe closing balance is %.2f\n", end_balance);
if (end_balance >= 50000)
printf ("*** It is time to invest some money!***\n\n");
else if (end_balance >= 15000)
printf ("*** Maybe you should consider a CD. ***\n\n");
else if (end_balance >= 1000)
printf ("*** Keep up the good work!***\n\n");
else if (end_balance >= 0)
printf ("*** Your balance is getting low!***\n\n");
printf ("***** Bank Record ******\n");
printf ("\nStarting Balance $%.2f\n", beg_balance);
for (i = 0; i < nm_deposits; i++)
{
printf ("Deposit #%d : $%.2f\n", i + 1, deposits[i]);
}
printf ("\n");
for (i = 0; i < nm_withdrawals; i++)
{
printf ("Withdrawal #%d : $%.2f\n\n", i + 1, withdrawals[i]);
}
printf ("Ending balance :$%.2f\n\n", end_balance);
}