Results 1 to 4 of 4

Thread: Two dimensional array to a function

  1. #1
    Join Date
    Apr 2009
    Posts
    79

    Two dimensional array to a function

    My program scan multidimensional array and sends it to a function that will handle data entry in it. when I send the "array [] [nbAmis]" I get an error that tells me nbAmis not reported.
    Code:
    # include <iostream>
     using namespace std;
    
     int main ()
     (
         [...]
      
         de(nbAmis, table);
       
         [...]
    
         return 0;
     )
    
     void de (nbAmis int, char array [] [nbAmis])
     (
         for (int i = 0; i <nbAmis; i + +)
         (
             court << "Name of friend" <<i +1 << "";
             cin>> array [i] [0];
         )
     )

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Two dimensional array to a function

    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    double f(double values[][4], int f);
    
    int main() {
      double beans[3][4] = {
                             { 2.0,  3.0,  4.0,  5.0},
                             { 55.0,  66.0,  77.0  88.0},
                             { 9.0, 10.0, 11.0, 12.0}
                           };
    
      cout << j(beans, sizeof beans/sizeof beans[0])<< endl;
      return 0;
    }
    
    double j(double array[][4], int size) {
      double sum = 0.0;
      for(int n = 0 ; n < size ; n++)       
        for(int k = 0 ; k < 4 ; k++)        
          sum += array[n][k];
      return sum;
    }

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Two dimensional array to a function

    Two-dimensional arrays are a little more complicated to use than one-dimensional ones. Whereas, one dimensional arrays can be visualized as a stack of elements, two dimensional arrays can be visualized as a multicolumn table or grid.

    Try like this
    Code:
    	  void demandeNoms (nbAmis int, char * array [])

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Two dimensional array to a function

    Two-dimensional arrays are declared by specifying the number of rows then the number of columns.
    Code:
    int  a[20][20];  (declares an int array of 20 rows and 20 columns)
    char ticTacToeBoard[4][4]; ( four rows and four columns of chars.)

Similar Threads

  1. Help with two dimensional array java
    By GlassFish in forum Software Development
    Replies: 3
    Last Post: 30-11-2009, 01:57 PM
  2. Dynamically allocate a two-dimensional array
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 24-10-2009, 11:43 AM
  3. Function that returns a 2d array
    By Zool in forum Software Development
    Replies: 3
    Last Post: 10-10-2009, 08:46 AM
  4. How to return an array from function
    By Rilex in forum Software Development
    Replies: 3
    Last Post: 02-10-2009, 09:18 AM
  5. Three Dimensional Array program in Java.
    By nonose in forum Software Development
    Replies: 3
    Last Post: 10-08-2009, 07:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,518,905.37406 seconds with 17 queries