So this is what i need to do and its not coming out right in my code. i need A function to calculate how long the balance will take to grow to a given value. This function is not part of the account class. It should take two arguments: an object of the account class and a target value. It should return how long should pass until the balance on the account object reaches the target value.
The account object must be a const reference parameter so that inside the function, you call the function to add interest to the balance as many times as needed without actually modifying the object.
I'm not getting how to make the object a const reference parameter.
This is my code. at the end i put a formula im not sure if i did it right. also whenever the program runs there is a zero next to balance and interest when i ask the user to enter there intial balance and interest.
class BankAccount
{
private:
double Balance;
double InterestRate;
public:
BankAccount();
BankAccount(double B, double IR){Balance=B; InterestRate=IR;}
void setB(double newB);
double getB() const;
void setIR(double IR);
double getIR() const;
void Deposit(double amount);
void Withdraw(double amount);
void addInterest(int years);
double addInterest();
};
BankAccount::BankAccount()
{
Balance=0;
InterestRate=0;
}
void BankAccount::setB(double newBalance)
{
Balance = newBalance;
}
void BankAccount::setIR(double newInterestRate)
{
InterestRate = newInterestRate;
}
double BankAccount::getB() const
{
return Balance;
}
double BankAccount::getIR() const
{
return InterestRate;
}
void BankAccount::Deposit(double amount)
{
Balance = Balance + amount;
}
void BankAccount::Withdraw(double amount)
{
Balance = Balance - amount;
}
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
int main ()
{
int year;
double getB;
double getIR;
double B = 0;
double IR =0;
double IRate;
double TV=0;
BankAccount Checking;
cout<<"Welcome to your BankAccount"<<endl;
cout<<" what is your initial Balance? " <<Checking.getB()<<endl;
cin>> B;
cout<<" what is your initial Interest Rate? " <<Checking.getIR()<<endl;
cin>> IR;
cout<<" what is your target Value?"<<endl;
cin >>TV;
{
year = ((TV/B-1)/IR);
}
cout << "Your initial account will take to grow to get interest" << endl;
}
By the way the object of my BankAccount Class is Checking.