Thread: Passing a double array to a function as an argument

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    	points[1][1] = 1;
    	points[1][2] = 2;
    	points[1][3] = 3;
    	points[1][4] = 4;
    	points[2][1] = 5;
    	points[2][2] = 6;
    	points[2][3] = 7;
    	points[2][4] = 8;
    	points[3][1] = 9;
    	points[3][2] = 10;
    	points[3][3] = 11;
    	points[3][4] = 12;
    
    	nextpoint[1][1] = 1;
    	nextpoint[1][2] = 2;
    	nextpoint[1][3] = 3;
    	nextpoint[1][4] = 4;
    	nextpoint[2][1] = 5;
        nextpoint[2][2] = 6;
        nextpoint[2][3] = 7;
    	nextpoint[2][4] = 8;
        nextpoint[3][1] = 9;
    	nextpoint[3][2] = 10;
        nextpoint[3][3] = 11;
        nextpoint[3][4] = 12;
    Arrays indices in C++ start at 0, so you must either expand your array, or change your initialization.
    > int points[3][4];
    This array goes from [0 thru 2][0 thru 3], so:
    Code:
    	points[0][0] = 1;
    	points[0][1] = 2;
    	points[0][2] = 3;
    	points[0][3] = 4;
    	points[1][0] = 5;
    	points[1][1] = 6;
    	points[1][2] = 7;
    	points[1][3] = 8;
    	points[2][0] = 9;
    	points[2][1] = 10;
    	points[2][2] = 11;
    	points[2][3] = 12;
    
    	nextpoint[0][0] = 1;
    	nextpoint[0][1] = 2;
    	nextpoint[0][2] = 3;
    	nextpoint[0][3] = 4;
    	nextpoint[1][0] = 5;
    	nextpoint[1][1] = 6;
    	nextpoint[1][2] = 7;
    	nextpoint[1][3] = 8;
    	nextpoint[2][0] = 9;
    	nextpoint[2][1] = 10;
    	nextpoint[2][2] = 11;
    	nextpoint[2][3] = 12;

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Also since you're checking attempt back in main(), you should pass this as a reference:

    void directionfunct(int &x, int &y, int coords[][13], int &letters, int ans,int cx, int cy, int j, int answer[12], int &ax, int &ay, int &attempt )

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Actually you may need to pass everything as a reference:

    void directionfunct(int &x, int &y, int coords[][13], int &letters, int &ans,int &cx, int &cy, int &j, int answer[12], int &ax, int &ay, int &attempt)

  4. #19
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Personally, I'd say that function (directionfunct) has way too many parameters. Also, the names of the parameters looks way to confusing too. But hey, it's your prog
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #20
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    Yes, it does have a lot of parameters, that is because I want to increment and decrement things, and it would be harder to do if the declaration is inside of the loop.

    I guess I will increase the array, I just like to start at 1.

  6. #21
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    Just posting the updated code before I stop programming for tonight.
    Last edited by Glirk Dient; 09-10-2003 at 03:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM