•
•
•
•
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
![]() |
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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:
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.
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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'
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 I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- VC++6.0 error C2059: syntax error : 'end of file' (C++)
- shouldn't this work?? (C++)
- syntax error after API call (C++)
- How to select data frm text file based on a condition (C)
- help with errors (C++)
- Loan Program needs work (C++)
- Weird build errors that are not even in my program Please help!! (C++)
- MFC problems (C++)
- overloading problem (C++)
Other Threads in the C++ Forum
- Previous Thread: help with Greatest common divisor
- Next Thread: Link List Insert problems



Linear Mode