I'm not using whole numbers in my program though. I'm using real numbers.
I also initialized my totals for each category to 0.00 so that it has a value to start off with before accumulations. However, this doesn't solve the problem as my program is still giving me crap values.
Here's the code to make it more easier:
/* Prob 10-3
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#include <stdlib.h>
double Get_Opening_Balance(); /* Gets the user's opening account balance */
void Choice_Menu(); /* Displays a menu for choices */
void Validate_Choice(double); /* Validates the user's choice from the menu */
double Deposit(double, double); /* Gets the user's deposit amount */
double Withdrawal(double, double); /* Gets the user's withdrawal amount */
double Check(double, double); /* Gets the user's check amount */
void Display_Results(double, double, double, double, double); /* Displays all results and totals */
main()
{
double open_balance_amount; /* The user's opening account balance */
/* Call functions */
open_balance_amount = Get_Opening_Balance();
Choice_Menu();
Validate_Choice(open_balance_amount);
}
double Get_Opening_Balance()
{
double open_acct_balance; /* The user's opening account balance */
/* Prompt the user */
printf("\nEnter the opening account balance: $");
scanf("%lf", &open_acct_balance);
if (open_acct_balance < 0.00)
exit(0);
else
return open_acct_balance;
}
void Choice_Menu()
{
/* Display menu */
printf("\nSelect your choice: ");
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\n");
}
void Validate_Choice(double opening_balance_amt)
{
char choice; /* The choice entered by the user */
double total_deposit_amt, /* The total amount deposited */
total_withdrawal_amt, /* The total amount withdrawn */
deposited_amt, /* The amount deposited */
withdrawn_amt, /* The amount withdrawn */
total_check_amt, /* The total check amount */
check_amt, /* The check amount */
account_balance, /* The current account balance */
closing_balance_amt; /* The closing balance amount */
/* Initialization */
total_deposit_amt = 0.00;
total_withdrawal_amt = 0.00;
total_check_amt = 0.00;
account_balance = 0.00;
account_balance += opening_balance_amt;
/* Get choice */
getchar();
choice = getchar();
/* Validate choice */
while (choice != 'q' || choice != 'Q')
{
if (choice == 'd' || choice == 'D')
{
account_balance = Deposit(deposited_amt, account_balance);
total_deposit_amt = account_balance - opening_balance_amt - total_withdrawal_amt - total_check_amt;
}
else if (choice == 'w' || choice == 'W')
{
account_balance = Withdrawal(withdrawn_amt, account_balance);
total_withdrawal_amt = -(account_balance - opening_balance_amt - total_deposit_amt - total_check_amt);
}
else if (choice == 'c' || choice == 'C')
{
account_balance = Check(check_amt, account_balance);
total_check_amt = -(account_balance - opening_balance_amt - total_deposit_amt - total_withdrawal_amt);
}
else if (choice == 'q' || choice == 'Q')
{
closing_balance_amt = account_balance;
Display_Results(opening_balance_amt, total_deposit_amt, total_withdrawal_amt, total_check_amt, closing_balance_amt);
exit(0);
}
else
printf("\nError! You must enter the following choices listed on the menu.");
Choice_Menu();
getchar();
choice = getchar();
}
}
double Deposit(double deposit_amount, double pres_account)
{
/* Prompt the user */
printf("\nEnter the amount to be deposited: $");
scanf("%lf", &deposit_amount);
pres_account += deposit_amount;
return pres_account;
}
double Withdrawal(double withdrawal_amount, double present_account_balance)
{
/* Prompt the user */
printf("\nEnter the amount to be withdrawn: $");
scanf("%lf", &withdrawal_amount);
if (withdrawal_amount > present_account_balance)
{
printf("\nWarning! The amount you have withdrawn exceeds your current account balance.\n");
exit(1);
}
else
{
present_account_balance -= withdrawal_amount;
return present_account_balance;
}
}
double Check(double check_amount, double curr_account)
{
/* Prompt the user */
printf("\nEnter the check amount $");
scanf("%lf", &check_amount);
if (check_amount > curr_account)
{
printf("\nWarning! The check amount exceeds your current account balance.\n");
exit(1);
}
else
{
curr_account -= check_amount;
return curr_account;
}
}
void Display_Results(double opening_balance, double total_deposit, double total_withdrawal, double total_check, double closing_balance)
{
/* Display the results */
printf("\nOPENING BALANCE: $%.2lf", opening_balance);
printf("\nTOTAL AMOUNT DEPOSITED: $%.2lf", total_deposit);
printf("\nTOTAL AMOUNT WITHDRAWN: $%.2lf", total_withdrawal);
printf("\nTOTAL CHECK AMOUNT: $%.2lf", total_check);
printf("\n----------------------------------");
printf("\nCLOSING BALANCE: $%.2lf", closing_balance);
printf("\n");
}