| | |
Homework - error C2059: syntax error : ']'
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
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.
C++ Syntax (Toggle Plain Text)
#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:
C++ Syntax (Toggle Plain Text)
small(array[0], sumc, sumr, r, h, w);
I'm here to prove you wrong.
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
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'
C++ Syntax (Toggle Plain Text)
#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:
C++ Syntax (Toggle Plain Text)
// 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 here to prove you wrong.
![]() |
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
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






