Need to get a value out of another function without returning it

Can someone explain to me how I can get the totalAmount out of getCustomerTotalAssets to use in the listCustomersWithHoldingsAbove function? I think I need to do something with passing by reference, but I don't know how to do that here. I am trying to write a function that lists all customers with holdings above a certain amount across all their accounts. Help would be greatly appreciated!

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
string Bank::getCustomerTotalAssets(int cusNum)
{
	int totalAmount = 0;
	Customer c = getCustomerByCustomerNumber(cusNum);
	for each(int aNum in c.accountNumbers)
	{
		Account a = getAccountByAccountNumber(aNum);
		totalAmount += a.balance;
	}
	return "Total balance of this customer across all accounts: " + intToDollarString(totalAmount);
}


string Bank::listCustomersWithHoldingsAbove(int amount)
{	
	string result;
	int totalAssets = 0;
	result += padRight("Customer#", '.', 9) + " ";
	result += padRight("Name", '.', 20) + " ";
	result += padRight("Birthdate", '.', 12) + " ";
	result += padRight("SS#", '.', 12) + "\n";

	result += padRight("", '_', 9) + " ";
	result += padRight("", '_', 20) + " ";
	result += padRight("", '_', 12) + " ";
	result += padRight("", '_', 12) + "\n";


	result += padRight("", '_', 9) + " ";
	result += padRight("", '_', 20) + " ";
	result += padRight("", '_', 12) + " ";
	result += padRight("", '_', 12) + "\n";


	return result;
}
Simplest solution would be to declare int totalAmount = 0; in you header file instead of in the function.
closed account (E0p9LyTq)
Ocen wrote:
I think I need to do something with passing by reference, but I don't know how to do that here.


Arguments passed by value and by reference: http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.