Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-11-2009
Member
 
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];
     )
 )
Reply With Quote
  #2  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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;
}
Reply With Quote
  #3  
Old 27-11-2009
Member
 
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 [])
Reply With Quote
  #4  
Old 27-11-2009
Member
 
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.)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 04:52 PM.