so I've got a lot of it done, I just need a hint as to the next step. So far I have the user entering a bank account, interest rate, and account balance. I need the user to enter an amount of years and the program will go through that many years and factor in the interest each year.
I want to do this in the main() for 4 objects of BankAccount.
here is what i have so far (it won't compile)
#include "stdafx.h"
#include<conio.h>
class BankAccount
{
friend ostream& operator<<(ostream&, const BankAccount&);
friend istream& operator>>(istream&, BankAccount&);
private:
double bankRate, accountBalance;
int bankAccount;
public:
BankAccount(int account=0, double balance=0, double rate=0);
//int phoneNumber;
//int getPhoneNumber(int n=0);
void setAccount(int);
void setBalance(double);
void setRate(double);
//void setLength(int const *length);
// void setRate(double const *rate);
//void setPhoneNumber(int const *num);
//int operator==(const PhoneCall& aPhone);
//ostream& operator<<(const PhoneCall& aPhone);
};
void BankAccount::setAccount(int a)
{
cout<<"enter the account number";
cin>>a;
return;
}
void BankAccount::setRate(double r)
{
cout<<"enter interest rate";
cin>>r;
return;
}
void BankAccount::setBalance(double b)
{
cout<<endl<<"enter account balance";
cin>>b;
return;
}
/*void PhoneCall::setLength(int const *length)
{
delete length;
//length = strdupnew(length);
}
void PhoneCall::setRate(double const *rate)
{
delete rate;
//rate=strdupnew(rate);
}
void PhoneCall::setPhoneNumber(int const *num)
{
delete num;
//num=strdupnew(num);
}
*/
BankAccount::BankAccount(int account, double balance, double rate)
{
bankAccount=account;
accountBalance=balance;
bankRate=rate;
}
/*int BankAccount::getPhoneNumber(int n)
{
phoneNumber=n;
return n;
}
*/
ostream &operator<<(ostream& out, const BankAccount& aBank)
{
return
out <<
"Bank Account: " << aBank.bankAccount <<endl<<
"Rate: " << aBank.bankRate <<endl<<
"Account Balance: " << aBank.accountBalance<<endl;
}
istream& operator>>(istream& in, BankAccount& aBank)
{
cout<<endl;
cout<<"Enter account number.";
in>>aBank.bankAccount;
cout<<endl<<"enter interest rate";
in>>aBank.bankRate;
cout<<endl<<"enter balance of account";
in>>aBank.accountBalance;
if(aBank.bankAccount<1000){
aBank.bankAccount=0;
}
if(aBank.bankAccount>9999){
aBank.bankAccount=0;
}
return in;
}
/*int PhoneCall::operator==(const PhoneCall& aPhone)
{
int truth=0;
if(phoneNumber=aPhone.phoneNumber)
truth=1;
return truth;
}
*/
int main()
{
BankAccount aBank(0, 0, 0);
cin>>aBank;
cout<< aBank;
//return 0;
//system("pause");
//getche();
/*
bool numberUsed;
BankAccount banks[4];
for( int i = 0; i < 4; i++ )
{
do
{
numberUsed = false;
cin >> banks[i];
for( int c = 0; c < 4; c++ ) //go through all phone calls
if( c != i ) //if is not the same phone call
if( banks[i].phoneNumber == calls[c].phoneNumber ) //if the numbers match
numberUsed = true; //number is taken
}
while(numberUsed); //do while numberUsed is true
}
for( int i = 0; i < 4; i++ )
{
cout << banks[i];
}
*/
//system("pause");
//return 0;
double years;
double balanceYear, balance1;
cout<<account<<endl;
balance1=balance;
int i=1;
cout<<"enter number of years";
cin>>years;
while(i<=years){
balanceYear=balance1+(balance1*rate);
cout<<"Year "<<i<<": the balance is "<<balanceYear<<endl;
balance1=balanceYear;
i++;
}
cout<<"The bank account number is "<<account<<"."<<endl;
cout<<"The bank account balance is "<<balance1<<"."<<endl;
getche();
}