Last error Im getting is error C2059: syntax error : ']'
Anyone have any ideas?


what it needs to do:write a c++ program that creates using a random number generation a 2 dimentional array of integers whos values range from -9 to 9. The array size is to be chosen by the user of the program. Your program will then print the sum of the numbers that are in the same rowor column as the smallest entry. If the smallest entry occurs more then once you can pick which you want it to use (*I am just trying to use the first*) The main program is to use a function that returns the row and column position of the smallest entry. Allow for arrays up to 10x10 and the user to input the array info.

#include <iostream>
#include <ctime> 
using namespace std;

void small(int [],int, int, int, int &,int &);

int main()
{
int r,c,q=0,h=0,w=0,array[10][10],sumr=0,sumc=0;

srand((unsigned)time(NULL));

cout << "Enter the hight of the array: ";
cin >> h;
cout << "Enter the width of the array: ";
cin >> w;
cout << endl;

for( r = 0 ; r < h ; r++ ){
	for( c = 0 ; c < w ; c ++ ){
		array[r][c] = rand()%19-9;
	}
}
for( r = 0 ; r < h ; r++ ){
	for( c = 0 ; c < w ; c ++ ){
		cout << array[r][c] << ' ';
	}
	cout << endl;
}
small(*array[], &sumc, &sumr, r, h, w);

return 0;
}

void small(int *array[],int &sumc,int &sumr,int r,int h, int w)
{
int i = -9;
cout << "The row sum is: " << sumr;
for(int r = 0 ; r < h ; r++ )
{
	for(int c = 0 ; c < w ; c ++ )
	{
		if(array[r][c]==i)
		{
			cout << "smallest row is: " << r << endl << "smallest column is: " << c;
			for (int g = 0; g < 10; g++)
			{
				sumc = sumc + array[r][g];
				sumr = sumr + array[g][c];
				
			}
		}
		else
			i--;
	}
}
}

>small(*array[], &sumc, &sumr, r, h, w);
The empty subscript only works for declarations. Either remove [], or remove * and change [] to [0]. Also, &sumc and &sumr are pointers, not int as small expects. This will compile, but it may not do what you want because you clearly have issues with the difference between single and multi-dimensional arrays:

small(array[0], sumc, sumr, r, h, w);

yea, I changed it around a little bit before but am now getting a new error.
error C2664: 'small' : cannot convert parameter 2 from 'int *__w64 ' to 'int'

#include <iostream>
#include <ctime> 
using namespace std;

void small(int [10][10],int, int, int, int &,int &);

int main()
{
int r,c,q=0,h=0,w=0,array[10][10],sumr=0,sumc=0;

srand((unsigned)time(NULL));

cout << "Enter the hight of the array: ";
cin >> h;
cout << "Enter the width of the array: ";
cin >> w;
cout << endl;

for( r = 0 ; r < h ; r++ ){
	for( c = 0 ; c < w ; c ++ ){
		array[r][c] = rand()%19-9;
	}
}
for( r = 0 ; r < h ; r++ ){
	for( c = 0 ; c < w ; c ++ ){
		cout << array[r][c] << ' ';
	}
	cout << endl;
}
small(array, &sumc, &sumr, r, h, w); // error C2664: 'small' : cannot convert parameter 2 from 'int *__w64 ' to 'int'

	getchar();
	getchar();
return 0;
}

void small(int array[10][10],int &sumc,int &sumr,int r,int h, int w)
{
int i = -9;
cout << "The row sum is: " << sumr;
for(int r = 0 ; r < h ; r++ )
{
	for(int c = 0 ; c < w ; c ++ )
	{
		if(array[r][c]==i)
		{
			cout << "smallest number is:" << array[r][c] << endl;
			for (int g = 0; g < 10; g++)
			{
				sumc = sumc + array[r][g];
				sumr = sumr + array[g][c];
				
			}
		}
		else
			i--;
	}
}
}

Okay, first, make sure that your function declaration and defintion match (copy/paste is useful). As it is, your declaration says that the last two parameters are references while the definition says that the second and third parameters are references and the last two are simple integers. Second, you only need to use the ampersand in a function call when the function expects a pointer:

// Declaration and definition types must match. Parameter names
// don't matter, but they can be useful documentation
void small(int array[10][10],int &sumc,int &sumr,int r,int h, int w);

void small(int array[10][10],int &sumc,int &sumr,int r,int h, int w)
{
}

small(array, sumc, sumr, r, h, w); // This will compile now

Narue is right.. must remove []

and make that as

small(array, sumc, sumr, r, h, w);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.