Array not Passing Parameter to function Main()

Hey guys, I am having problems passing array values from a sub function back to my main function.

For Ex:

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
int getInventory (vector<string> u, vector<string> v, vector<double> w, vector<double> x, vector<int> y, ifstream& q)
/* 
productName = U || itemId = V || mPrice = W || sPrice = X || stock = Y
*/
{
//Calling the File into the Program.
ifstream inData;
inData.open ("input.txt");
		
//Check If file exists		
if (inData)
{
	
//controlling the appearance of cout.
cout << setprecision(2) << fixed << showpoint;
				
//Updating the Array with each of the appropriate Values.
int i;
for (i = 0; i < 5; i++)
{
inData >> u[i] >> v[i] >> w[i] >> x[i] >> y[i];

/*cout <<" " << u[i] << " " << v[i] << " " << "$" << w[i]
<< " " << "$" << x[i] << " " << y[i];*/
cout << endl;
}
cout << "Manufacture Price = $" << w[4];
return 0;
}


This returns the correct manufacture price.
But when I call the same value from the main function it displays 0.00

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
int main()
{
	// BEGIN getInventory Variables (coded by DL)
	vector<string> productName(5);
	vector<string> itemId(5);
	vector<double> mPrice(5);
	vector<double> sPrice(5);
	vector<int> stock(5);
	int choice;
	string customerName;
	ifstream inData;
	
	
	// END getInventory Variables
	
	// BEGIN DL's Functions
		 getInventory(productName, itemId, mPrice, sPrice, stock, inData); // Calls getInventory Function
		 welcome(customerName);// Calls CSR (customer service Rep) Function
		 findChoice(choice, customerName); // Finds user's Choice
		 choiceCheck(choice, customerName); // Checks if user input is Valid
		 executeChoice(itemId, sPrice, choice, stock, customerName); // Performs user's choice
		 buyItem(productName, itemId, sPrice, stock);
		 
	 // END DL's Functions
	
	cout << "Manufacture Price: " << mPrice[4];
	
	return 0;


Any Ideas?
Last edited on
If you want any of the changes made inside your function to be reflected in your calling function you'll need to pass the variables by reference, instead of passing by value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iosteam>

void someFunct(int &byReference, int byValue)
{
   byReference += 10;
   byValue += 10;

   cout << byReference << " " << byValue << endl;
}


int main()
{
   int a =  0; b = 100;
   someFunct(a, b);

   cout << "a in main(): " <<  a << " b in main(): " << b << endl;

   return 0;
}
Topic archived. No new replies allowed.