Hey Everyone! I have two - hopefully simple - problems that I need help with. I wrote an atm program in c++ that works except for two things...
(1) the part where I calculate the balance based on the interest rates for the checkings and savings accounts need to be put into an overloaded function and I dont know how to do that. I understand with an overloaded function both functions will have the same name but different types or number of arguments. But don't know exactly how to apply that And
(2) When the user inputs "e" or "E" for Exit I dont what the program to ask "Make another transaction?" I just want it to go to "Thank you for using MY Bank ATM!"
Here is my code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//void calculate_balance(
//void calculate_balance(
void exit();
int main()
{
double savings = 1000;
double checking = 1000;
double withdraw_checking = 0;
double withdraw_savings = 0;
double deposit_checking = 0;
double deposit_savings = 0;
double check_amount;
string choice, yesno, depos_check, depos_savings;
cout << "\n *** MY Bank ATM ***";
do
{
cout << "\n\nChoose C)hecking S)avings B)alance Ca)sh A Check E)xit: ";
cin >> choice;
// If choice is for the balance ...display totals of accounts.
if (choice == "b" || choice == "B")
{
cout << "Checking Balance: $" << setw(8) << setprecision(2) << fixed
<< checking << '\n';
cout << "Savings Balance: $" << setw(8) << setprecision(2) << fixed
<< savings << endl;
}
// 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 = - withdraw_checking + checking + (checking * .05);
}
// 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 = deposit_checking + checking + (checking * .05);
}
}
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 = - withdraw_savings + savings + (savings * .025);
}
// if withdrawal 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 = deposit_savings + savings + (savings * .025);
}
// If user asked to cash a check...input amount of check and display .
if (choice == "ca" || choice == "Ca")
{
cout << "Enter amount of Check: " << setw(8) << setprecision(2) << fixed <<
check_amount << '\n';
cout << "Here is your cash: " << setw(8) << setprecision(2) << fixed <<
savings << endl;
}
if (choice == "e" || choice == "E")
{
exit();
}
}
// Asks user if they wish to perform another task
cout << "\n\nMake another transaction? (Y/N):";
cin >> yesno;
}
while (yesno == "y" || yesno == "Y");
cout << "Thank you for using MY Bank ATM!"<<endl;
return 0;
}
void exit()
{
cout << "Thank you for using MY Bank ATM!" <<endl;
}