User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,745 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,818 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 19844 | Replies: 3
Reply
Join Date: Jun 2005
Posts: 3
Reputation: renork is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
renork renork is offline Offline
Newbie Poster

Homework - error C2059: syntax error : ']'

  #1  
Jul 3rd, 2005
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--;
	}
}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,340
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 29
Solved Threads: 460
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: Homework - error C2059: syntax error : ']'

  #2  
Jul 3rd, 2005
>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);
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Jun 2005
Posts: 3
Reputation: renork is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
renork renork is offline Offline
Newbie Poster

Re: Homework - error C2059: syntax error : ']'

  #3  
Jul 3rd, 2005
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--;
	}
}
}

Reply With Quote  
Join Date: Sep 2004
Posts: 6,340
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 29
Solved Threads: 460
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: Homework - error C2059: syntax error : ']'

  #4  
Jul 3rd, 2005
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
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:48 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC