New problem:
I have a program that requires me to check to see if the amount withdrawn from an account in regular cash withdrawals or checks exceeds the amount already present. For instance, if I had $2000 in my account, deposited $1000, withdrew $3000 in cash, and another $3000 in checks, my closing balance would come to $-3000.
I have an
if statement that checks to see if the closing balance falls below $0.00 and if it does, displays the amount that has exceeded.
However, for some strange reason, my program was able to display the amount a couple of times but afterwards, mysteriously stopped when I put a
#define statement for "0.00". Even when I tried to undo it, the statement still didn't appear. Here's the code:
/* Prob 8-10
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#define ACCOUNT_LIMIT 0.00 /* The limit of the account between positive and negative balance */
main()
{
int choice; /* The user's selected choice */
float opening_balance, /* The opening account balance */
total_deposit, /* The total of all deposits */
deposit, /* The amount of the deposit */
total_check, /* The total of all checks */
check, /* The amount of the check */
total_withdrawal, /* The total of all withdrawals */
withdrawal, /* The amount of the withdrawal */
closing_balance; /* The closing account balance */
/* Prompt the user for the opening balance */
printf("Enter your opening account balance for the month: $");
scanf("%f", &opening_balance);
/* Display menu */
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\nMake your selection: ");
getchar();
choice = getchar();
/* Perform action based on choice */
do
{
if (choice == 'd' || choice == 'D')
{
printf("\nEnter the amount of the deposit: $");
scanf("%f", &deposit);
total_deposit += deposit;
}
else if (choice == 'c' || choice == 'C')
{
printf("\nEnter the amount of the check: $");
scanf("%f", &check);
total_check += check;
}
else if (choice == 'w' || choice == 'W')
{
printf("\nEnter the amount of the withdrawal: $");
scanf("%f", &withdrawal);
total_withdrawal += withdrawal;
}
else
printf("\nError. You must select the following: ");
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\nMake your selection: ");
getchar();
choice = getchar();
} while (!(choice == 'q' || choice == 'Q'));
/* Perform calculation */
closing_balance = opening_balance + total_deposit - total_withdrawal - total_check;
/* Check if account is overdrawn */
if (closing_balance < ACCOUNT_LIMIT)
{
printf("\nWARNING: Your account has been overdrawn by $%.2f", closing_balance + ACCOUNT_LIMIT);
printf("\n");
}
/* Display totals */
printf("\nOPENING BALANCE: $%.2f", opening_balance);
printf("\nTOTAL DEPOSIT: $%.2f", total_deposit);
printf("\nTOTAL WITHDRAWAL:$%.2f", total_withdrawal);
printf("\nTOTAL CHECKS: $%.2f", total_check);
printf("\n------------------------");
printf("\nCLOSING BALANCE: $%.2f", closing_balance);
}
Can you figure out why the
if statement that checks for the overdrawn amount in the account won't appear in my program? Because I'm just positively baffled here.
Another thing, the program instructions ask for me to display a warning
at any time during the program a withdrawal or check results in a negative balance. Does the program want me to check for an over withdrawal each time the check amount or cash withdrawal falls below $0.00 or does it have to be after the closing balance has been computed?
Take your time guys. I think I said a mouthful.