Hello! I am having difficulties with my program. Basically, it should output the
ID: 3626505 • Letter: H
Question
Hello!I am having difficulties with my program. Basically, it should output the initial balance, balance after withdrawal, balance after deposit depending on which user ID is inputted. I can't seem to get the makeWithdraw and makeDeposit functions output the correct amounts. What am I doing wrong?? Any help will be greatly appreciated! Thanks in advance.
#include <iostream>
using namespace std;
class BankAccount
{
private:
int userId;
double accountBalance;
public:
double makeWithdraw();
double makeDeposit();
BankAccount::BankAccount(double initialBalance)
{
accountBalance = initialBalance;
}
BankAccount::BankAccount()
{
}
double BankAccount::GetBalance()
{
return accountBalance;
}
void BankAccount::SetBalance (double balance)
{
accountBalance = balance;
}
double makeWithdraw(double GetBalance)
{
return GetBalance = (accountBalance-200.33);
}
double makeDeposit(double GetBalance)
{
return GetBalance = (accountBalance-301.25);
}
};
int main(){
BankAccount bankaccount (0);
double makeWithdraw, makeDeposit, balance;
int getUserid;
do
{
cout << "Enter userID: " ;
cin >> getUserid;
if (getUserid==1234)
{
BankAccount CustomerOne(500);
cout << "Customer: Sally, ID: 1234, Account Balance: $" ;
cout << CustomerOne.GetBalance() << endl;
}
else if (getUserid==1338)
{
BankAccount CustomerTwo(600);
cout << "Customer: Billy, ID: 1338, Account Balance: $" ;
cout << CustomerTwo.GetBalance() << endl;
}
else if (getUserid==3333)
{
BankAccount CustomerThree(1000);
cout << "Customer: Crystal, ID: 3333, Account Balance: $" ;
cout << CustomerThree.GetBalance() << endl;
}
makeWithdraw = bankaccount.makeWithdraw(balance);
makeDeposit = bankaccount.makeDeposit(balance);
cout << makeWithdraw << endl;
cout << makeDeposit << endl;
} while (getUserid!= 0) ;
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks
hope this helps
#include <iostream>
using namespace std;
class BankAccount
{
private:
int userId;
double accountBalance;
public:
BankAccount::BankAccount(double initialBalance)
{
accountBalance = initialBalance;
}
BankAccount::BankAccount()
{
}
double BankAccount::GetBalance()
{
return accountBalance;
}
void BankAccount::SetBalance (double balance)
{
accountBalance = balance;
}
double makeWithdraw()
{accountBalance-=200.33;
return accountBalance;
}
double makeDeposit()
{accountBalance+=301.25;
return accountBalance;
}
};
int main(){
BankAccount bankaccount (0);
double makeWithdrawal, makeDep, balance;
int getUserid;
do
{
cout << "Enter userID: " ;
cin >> getUserid;
if (getUserid==1234)
{
BankAccount CustomerOne(500);
cout << "Customer: Sally, ID: 1234, Account Balance: $" ;
cout << CustomerOne.GetBalance() << endl;
bankaccount=CustomerOne;
}
else if (getUserid==1338)
{
BankAccount CustomerTwo(600);
cout << "Customer: Billy, ID: 1338, Account Balance: $" ;
cout << CustomerTwo.GetBalance() << endl;
bankaccount=CustomerTwo;
}
else if (getUserid==3333)
{
BankAccount CustomerThree(1000);
cout << "Customer: Crystal, ID: 3333, Account Balance: $" ;
cout << CustomerThree.GetBalance() << endl;
bankaccount=CustomerThree;
}
makeWithdrawal = bankaccount.makeWithdraw();
makeDep = bankaccount.makeDeposit();
cout << makeWithdrawal << endl;
cout << makeDep << endl;
} while (getUserid!= 0) ;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.