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();
 
      }

>here is what i have so far (it won't compile)
So what do you want us to do? Finish it up for you, tie it up with a pretty little bow, and send it to your teacher with your name on it? Why don't you try posting what errors you're getting, explain what you did to solve them, what you learned along the way, and ask a specific question so that we don't treat you like a homework cheating leech.

kthxbye

Edited 7 Years Ago by Narue: n/a

my feelings are hurt...i am not a leech

in this updated program attempt, i would specifically like to know how to call the BankAccount::interest into the actual main() program at the end.

#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 interest();
	//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;
	}

*/

	void BankAccount::interest()
	{
		double balance1, balanceYear;
		int i=1;
		balance1=accountBalance;
		while(i<=5){
		balanceYear=balance1+(balance1*bankRate);
		cout<<"Year "<<i<<": the balance is "<<balanceYear<<endl;
		balance1=balanceYear;
		i++;
		}
	}


	
	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++;
	}

*/

	
	aBank.interest;

	  getche();
 
      }

so i figured out out to get my program to run and it works...theres just one last part that im not sure how to do... as of right now, the user is able to enter 1 bank acccount and all the information, how do i make it so they can enter a few of them?

#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 interest();
	//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;
	}

*/

	void BankAccount::interest()
	{
		double balance1, balanceYear;
		int i=1;
		balance1=accountBalance;
		while(i<=5){
		balanceYear=balance1+(balance1*bankRate);
		cout<<"Year "<<i<<": the balance is "<<balanceYear<<endl;
		balance1=balanceYear;
		i++;
		}
	}


	
	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++;
	}

*/

	
	aBank.interest();

	  getche();
 
      }

Well, ignoring that your input doesn't do much to protect the user from themselves (for example, enter "fred" when it asks for the account number and see what happens)...

Do you know in advance (or can you ask) how many they want to enter?

If you could, you could wrap the input and output in a loop. Something like the following where numberToEnter is an integer that was set prior to the loop:

BankAccount aBank(0, 0, 0);
		for (int acctindex = 0; acctindex < numberToEnter; acctindex++)
		{
			cin>>aBank;
			cout<< aBank;
			aBank.interest();
		}

That re-uses the aBank instance so at the end, you still only have one instance, but you have filled it and output from it multiple times.

This question has already been answered. Start a new discussion instead.