-
Please Help Me Soon
i need to know the correct structure for passing a 2d array
i need this for a class i have and i'm not sure how to do it.
the code i have is:
void getinfo(string, double[4][3], int[4]);
void main(void)
{
double test_scores[4][3];
int credit_hours[4];
//char lettergrade[4];
string student_name;
//do
{
getinfo(student_name, test_scores, credit_hours);
}
//while (chioce != 'Q');
}
void getinfo(string /*out*/ & name, double /*out*/ scores[][3], int /*out*/ hours[])
{
int i;
cout << "Enter the student's name: ";
getline(cin, name);
cin.ignore();
for(i = 1; i <= 4; i++)
{
cout << "Please enter the number of credis for this class: ";
cin >> hours[i];
cout << hours[i];
}
}
this is only the beginning of the code and the rest will be easy, but i'm getting different errors relating to the passing of the 2d array test_scores (scores is the parameter in getinfo)
please help me!! thanx in advance
-
Prototype the function like this:
void getinfo(string, double[][3], int[]);
-
when i do that though, i get a linking error about unresolved externals
a6.obj : error LNK2001: unresolved external symbol "void __cdecl getinfo(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double (* const)[3],int * const)" (?getinfo@@YAXV?$basic_string@DU?$char_traits@D@st d@@V
?$allocator@D@2@@std@@QAY02NQAH@Z)
Debug/a6.exe : fatal error LNK1120: 1 unresolved externals
thanx for your help, don't give up please
-
correction: i get that anyway, regardless of whether or not the prototype has values in the brackets or not
-
Hmm... I have actually never passed 2D pointers to functions before. I'll try it when I come home and see if I can solve it.
-
thanx for the help but it will be too late, this is due in 3 hrs (who ever said college kids didn't procrastinate was a liar)
-
I see where the error is now. Put a '&' after 'string' in the prototype.
-
u just saved my life :) thank you very much
-
The prototype is nothing more than a copy of the first line of your implementation with a semicolon. If you get these errors, take the head of your function and copy it as your prototype. Easy as that.
-
Yes, that's how I use to solve it.