I have this banking program that has a savings, checking account set up. The user has 4 options.
Checking, Saving, Balance, and monthly maintenance.
The checking option is all correct and never comes out weird...u can deposit everything and withdraw without any probs.
If i do that -- then i ask for an account balance -- it shows the correct numbers for the checking account(lets say i deposited 100, it says $100) and for savings it says $0.
Now if i try depositing money to the savings account, then try viewing its balance it comes out as 1.4+000e something or other, not the 100 i deposited. I know i had a similiar problem before and it was because i didnt tell a variable to equal zero to begin with.....
Here is my program(without the maintenance section, havent tried that yet!) please take a look and help me find out where the prob is. Ive been trying to tackle this for a good few hours, all the code here is written by me so i have legit. tried this thing...and seemed to have done a good job for a first timer....
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double savings = 0, checking = 0, withdraw_checking = 0, withdraw_savings = 0, deposit_checking = 0, deposit_savings = 0;
string choice, yesno, depos_check, depos_savings;
cout << "\n *** ACME Bank ATM ***";
do
{
cout << "\n\nChoose C)hecking S)avings B)alance M)onthly Maintenance: ";
cin >> choice;
// If choice is for the balance ...display totals of accounts.
if (choice == "b" || choice == "B")
{
cout << "Checking Balance: $" << checking << setiosflags(ios:: showpoint) << setprecision(2);
cout << "\nSavings Balance: $" << savings;
}
// If choice is for Checking account, display option to withdraw/deposit
if (choice == "c" || choice == "C")
{
cout << "\nW)ithdrawal or D)eposit? :";
cin >> depos_check;
// If user asked to withdraw cash
if (depos_check == "w" || depos_check == "W")
{
cout << "Enter amount to withdraw from checking account:";
cin >> withdraw_checking;
// If withdraw leaves money in account....can do action.
if (checking - withdraw_checking > 0)
{
checking = checking - withdraw_checking;
}
// if withdrawal is makes account under 0, then says sorry cannot do.
else
{
cout << "Cannot withdraw $" << withdraw_checking << ".00 from account( $" << checking << ".00 )";
cout << "\nPlease deposit more funds or try a smaller withdrawal.";
}
}
// If user asked to deposit funds. Asks how much then adds deposited funds to account (checking)
if (depos_check == "d" || depos_check == "D")
{
cout << "Enter amount to deposit:";
cin >> deposit_checking;
checking = checking + deposit_checking;
}
}
if (choice == "s" || choice == "S")
{
cout << "\nW)ithdrawal or D)eposit? :";
cin >> depos_savings;
// If user asked to withdraw cash
if (depos_savings == "w" || depos_savings == "W")
{
cout << "Enter amount to withdraw from savings account:";
cin >> withdraw_savings;
// If withdraw leaves money in account....can do action.
if (savings - withdraw_savings > 0)
{
savings = savings - withdraw_savings;
}
// if withdrawal is makes account under 0, then says sorry cannot do.
else
{
cout << "Cannot withdraw $" << withdraw_savings << ".00 from account( $" << savings << ".00 )";
cout << "\nPlease deposit more funds or try a smaller withdrawal.";
}
}
// If user asked to deposit funds. Asks how much then adds deposited funds to account (savings)
if (depos_savings == "d" || depos_savings == "D")
{
cout << "Enter amount to deposit:";
cin >> deposit_savings;
savings = savings + deposit_savings;
}
}
// Asks user if they wish to perform another task
cout << "\n\nDo another? (Y/N):";
cin >> yesno;
}
while (yesno == "y" || yesno == "Y");
cout << "Thank you for using ACME Bank ATM!";
cin.get();
cin.get();
return 0;
}
Also how do i make the program add 2 decimal places are the number i put in. Becaue if i put in 100 which my teacher wants me to do, then i check the balance it only displays $100. Now ive tried playing around with a few things as you will see under the check balance thing...could you take a look at that too!
Tanks