Thread: Please Help Me Soon

  1. #1
    Unregistered
    Guest

    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

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Prototype the function like this:

    void getinfo(string, double[][3], int[]);
    // Gliptic

  3. #3
    Unregistered
    Guest
    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

  4. #4
    Unregistered
    Guest
    correction: i get that anyway, regardless of whether or not the prototype has values in the brackets or not

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    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.
    // Gliptic

  6. #6
    Unregistered
    Guest
    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)

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    I see where the error is now. Put a '&' after 'string' in the prototype.
    // Gliptic

  8. #8
    Unregistered
    Guest
    u just saved my life thank you very much

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    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.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Yes, that's how I use to solve it.

Popular pages Recent additions subscribe to a feed