[ERROR] invalid types int[int] - :(

Hey guys, I searched the forum for this but none of them helped me solve my problem.

I keep getting this error, I know the problem is involving the arrays but I have no idea how to fix it.

Can you guys show me whats going on?

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
int getInventory (string& u[5], int& v[5], double& w[5], double& x[5], int& y[5]);

int main ()
{
	// Variables Listed. (code by DL)
	string productName[5];
	int itemId[5];
	double mPrice[5];
	double sPrice[5];
	int stock[5];
	
	getInventory(productName, itemId, mPrice, sPrice, stock);
	
	return 0;
}

int getInventory (string& u[5], int& v[5], double& w[5], double& x[5], int& y[5])

/* 
	productName = U
	itemId = V
	mPrice = W
	sPrice = X
	stock = Y
	i = Z
*/
{
	
	
	//Calling the File into the Program.
	ifstream inData;
		inData.open ("input.txt");
		
		//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 << endl;
			
			cout <<" " << u[i] << " " << v[i] << " " << "$" << w[i] << " " << "$" << x[i] << " " << y[i];
			cout << endl << endl;
			}
		
		// Error correction Statement, if File !FOUND.
		if (!inData)
			{
			cout << endl << endl;
			cout << "Sorry, the file does not exist. Please Check" << endl;
			return 1;
			}
}
Which line is it on? How can the error be on line 55?
Arrays are by default passed as references so remove the ampersands(&). Also your function does not always return a value. You should have a return for if it succeeds and fails not only if it fails.
Bob, the error is not on line 55 that was a comment of what the following statement does. but it says the errors are on lines 7, 48, and 51
OK, thank you.
Fix the error on line 7 and 23 as I mentioned. You can either 1) remove ampersand, 2) do something like string (&u)[], ... 3) string *&u, ...
http://stackoverflow.com/questions/10007986/c-pass-an-array-by-reference
Giblit, Thanks for your input.

I just tried updating the code, but the problem persists.

I also tried making the function VOID, and removing returns since I only need to reference the array parameters -- no luck.

Your Thoughts?

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
void getInventory (string u, int v, double w, double x, int y);

int main ()
{
	// Variables Listed. (code by DL)
	string productName[5];
	int itemId[5];
	double mPrice[5];
	double sPrice[5];
	int stock[5];
	
	getInventory(productName, itemId, mPrice, sPrice, stock);
	
	return 0;
}

void getInventory (string u, int v, double w, double x, int y)

/* 
	productName = U
	itemId = V
	mPrice = W
	sPrice = X
	stock = Y
	i = Z
*/
{
	
	
	//Calling the File into the Program.
	ifstream inData;
		inData.open ("input.txt");
		
		//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 << endl;
			
			cout <<" " << u[i] << " " << v[i] << " " << "$" << w[i] << " " << "$" << x[i] << " " << y[i];
			cout << endl << endl;
			}
		
		// Error correction Statement, if File !FOUND.
		if (!inData)
			{
			cout << endl << endl;
			cout << "Sorry, the file does not exist. Please Check" << endl;
			//return 1;
			}
}
you removed the ampersands and the brackets([]). You need either brackets([]) after or an asterisk(*) before variable name. int getInventory (string u[], int v[], double w[], double x[], int y[]) or int getInventory (string (&u)[], int (&v)[], double (&w)[], double (&x)[], int (&y)[]) or int getInventory (string *u, int *v, double *w, double *x, int *y) or ]int getInventory (string *&u, int *&v, double *&w, double *&x, int *&y) should work.
Giblet, The problem in line 7 is gone now -- but the problems in line 48, and 51 remain.
There shouldn't be any errors on line 48 and 51 if you properly fixed the errors on line 7 and 23. Will you please post the newest code?
AWESOME! Thanks Giblit!

The first line you suggested fixed the code!

But now, I don't understand how it fixed it, would you mind explaining?

UPDATED CODE:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
void getInventory (string u[], int v[], double w[], double x[], int y[]);

int main ()
{
	// Variables Listed. (code by DL)
	string productName[5];
	int itemId[5];
	double mPrice[5];
	double sPrice[5];
	int stock[5];
	
	getInventory(productName, itemId, mPrice, sPrice, stock);
	
	return 0;
}

void getInventory (string u[], int v[], double w[], double x[], int y[])

/* 
	productName = U
	itemId = V
	mPrice = W
	sPrice = X
	stock = Y
*/
{
	
	
	//Calling the File into the Program.
	ifstream inData;
		inData.open ("input.txt");
		
		//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 << endl;
			
			cout <<" " << u[i] << " " << v[i] << " " << "$" << w[i] << " " << "$" << x[i] << " " << y[i];
			cout << endl << endl;
			}
		
		// Error correction Statement, if File !FOUND.
		if (!inData)
			{
			cout << endl << endl;
			cout << "Sorry, the file does not exist. Please Check" << endl;
			//return 1;
			}
} 
When you pass an array you are passing the address of it not the actual block of memory. So when you modify an array in a function you modify it outside also.

These might help you to understand why it works.
http://www.cplusplus.com/doc/tutorial/arrays/ --towards the bottom
http://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm
http://www.learncpp.com/ --chapter 6 and 7
Awesome, Thanks for your help!
Topic archived. No new replies allowed.