Objects in vector to variables

I have a Class with balance and interest that are objects in a vector. I want theese values in variables. How can I achieve this. This code below doesnt seems to work and I don´t understand why.. Can anybody correct my code or help me? Thank you / P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  void interest(vector<Account>&accounts)
{

	double balance_tmp;
	double interest_tmp;
	double final_balance;

		for (unsigned int i = 0; i < accounts.size(); i++)
		{
			balance_tmp = accounts[i].Balance() << endl;
			interest_tmp = accounts[i].Interest() << endl << endl;

			 final_balance = (balance_tmp * ((interest_tmp * 0.01) + 1.00));
			 
		}
}
Last edited on
Read below
Last edited on
What is your member function Balance and Interest Returning ?
What is an insertion operator << doing in assignment statement ?
Thank god basetwo, I´ve coded for several Days now and stared myself blind. You are so right so right. Hahaha what in hell hehe ;)

Well for your curiosity. Check this code, different types in a class inserted in a vector with this class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Account
{
public:
	Account() : number(0), owner(""), balance(0), interest(0) {}
	Account(const int _number, string &_owner, double _balance, double _interest) : number(_number), owner(_owner), balance(_balance), interest(_interest) {}
	Account(const Account&rhs) : number(rhs.number), owner(rhs.owner), balance(rhs.balance), interest(rhs.interest) {}
	Accountoperator=(const Account&rhs)
	{
		if (&rhs == this)
		{
			return *this;
		}
		
		number = rhs.nummer;
		owner= rhs.owner;
		balance = rhs.balance;
		interest = rhs.interest;

		return *this;
		
	}
	
	//Metod: Sets the necessary info
	void SetInfo(const int _number, string &_owner, double _balance, double _interest)
	{
		number = _number;
		owner= _owner;
		balance = _balance;
		interest = _interest;
	}

	// Accessor functions
	
	int Number() const { return number; }
	const string &Owner() const { return owner;}
	double Balance() const { return balance; }
	double Interest() const { return interest; }

//Member variables
private:
	int number;
	string owner;
	double balance;
	double interest;
};
Solved it, now the interest is paid to evevry account in the vector. Here is the function in Swedish as thanks for your help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void ranteutbetalning(vector<Konto>&konton)
{
	int nummer;
	string innehavare;
	double saldo;
	double rantesats;	

	double saldo_tmp;
	double slutligt_saldo;	

		for (unsigned int i = 0; i < konton.size(); i++)
		{
			nummer = konton[i].Nummer();
			innehavare = konton[i].Innehavare();

			saldo_tmp = konton[i].Saldo();
			rantesats = konton[i].Rantesats();

			konton.erase(konton.begin());

			slutligt_saldo = (saldo_tmp * ((rantesats * 0.01) + 1.00));

			saldo = slutligt_saldo;

			konton.push_back(Konto(nummer, innehavare, saldo, rantesats));

			cout << konton[i].Nummer() << endl;
			cout << konton[i].Innehavare() << endl;
			cout << konton[i].Saldo() << endl;
			cout << konton[i].Rantesats() << endl << endl;

		}
}
Topic archived. No new replies allowed.