i am having a problem in my function, i need someone to explain or fix my problem.
and r my arrays correct.

#include<iostream>  
    #include<iomanip>  
    using namespace std;  
    void display_draw(int mega[12][6], int draw_index);  
    int main()  
      
          
    {  
        //int i;  
       const int NUMROWS=12;  
       const int NUMCOLS=6;  
       int draw_index;  
       int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34,  
                                   1,20,22,29,41,35,  
                                   1,3,12,19,20,28,  
                                   1,22,33,43,52,36,  
                                   8,14,22,39,50,44,  
                                   10,22,36,50,53,39,  
                                   11,17,25,36,42,13,  
                                   5,14,25,47,49,36,  
                                   8,9,14,38,44,36,  
                                   3,5,15,43,51,11,  
                                   8,9,43,44,54,27,  
                                 4,19,24,32,54,5};  
    

   cout<<"please put in row"<<endl;  
   cin>>draw_index;  
    display_draw(val,draw_index);  
       return 0;  
   }  
  void display_draw(int mega[12][6], int draw_index)  
       {int i;  
           for(i=0;i<mega[12];i++)  
       {  
                       if(mega[i]==draw_index)  
                           cout<<endl;  
           }
  
       return;  
   }

It's always a good idea to post the specific errors you get from the compiler.

I think you may be initializing your array incorrectly. Listing all the elements as you have done may not be the proper way to populate a multidimensional array.

void display_draw(int mega[12][6], int draw_index);

This is wrong (I think). You can't have an array as a parameter of a function (at least not the way you're doing it here). It's possible with pointers. Change the prototype (and the implementation) to:

void display_draw(int* mega, int draw_index);

Change the call to the function from display_draw(val,draw_index); to display_draw(&val,draw_index); You're also trying to refer to an element in a two dimensional array in display_draw with only one index, like mega[12] and mega[i] . I'm not sure exactly what you're trying to do, but I don't think that's the way to do it.

c:\documents and settings\loin\my documents\visual studio 2008\projects\hh\hh.cpp(34) : error C2446: '<' : no conversion from 'int *' to 'int'
        There is no context in which this conversion is possible
c:\documents and settings\loin\my documents\visual studio 2008\projects\hh\hh.cpp(34) : error C2040: '<' : 'int' differs in levels of indirection from 'int [6]'
c:\documents and settings\loin\my documents\visual studio 2008\projects\hh\hh.cpp(36) : error C2446: '==' : no conversion from 'int' to 'int *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\loin\my documents\visual studio 2008\projects\hh\hh.cpp(36) : error C2040: '==' : 'int [6]' differs in levels of indirection from 'int'

my prototype parameters are correct , sojmething wrong in the fucntion, not in main
these are my errors ,

It's entirely legal prototype in C and C++:

void display_draw(int mega[12][6], int draw_index);

It's legal to initialize 2D array with one-level value list although better use more explicit form:

int val[NUMROWS][NUMCOLS] =
{
    { /* row 0 data list               */ },
     .....
    { /* row NUMROWS-1 data list*/}
};

Alas, I don't understand display_draw body contents and specifications...

i need to display the row;
i need to fix one error

error C2440: '=' : cannot convert from 'int' to 'int [6]'

here' my code which i have fixed

#include<iostream>  
    #include<iomanip>  
    using namespace std;  
    void display_draw(int mega[12][6], int draw_index);  
    int main()  
      
          
    {  
        //int i;  
       const int NUMROWS=12;  
       const int NUMCOLS=6;  
       int draw_index;  
       int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34,  
                                   1,20,22,29,41,35,  
                                   1,3,12,19,20,28,  
                                   1,22,33,43,52,36,  
                                   8,14,22,39,50,44,  
                                   10,22,36,50,53,39,  
                                   11,17,25,36,42,13,  
                                   5,14,25,47,49,36,  
                                   8,9,14,38,44,36,  
                                   3,5,15,43,51,11,  
                                   8,9,43,44,54,27,  
                                 4,19,24,32,54,5};  
    

   cout<<"please put in row"<<endl;  
   cin>>draw_index;  
    display_draw(val,draw_index);  
       return 0;  
   }  
  void display_draw(int mega[12][6], int draw_index)  
       {int i;  
           for(i=0;i<12;i++)  
       {  
                       if(mega[i])  
                            mega[i]=draw_index;                      
                                 }
  
       return;  
   }

mega = draw_index;

draw_index is a single int.
mega is an array of 6 int.
you can't assign a single int to an array of int since they aren't the same type.

Since you don't comment on the intent of display_draw() I can't help you correct the problem, only point it out. I could assume what you might be trying to do, but I think it best if you explain, and in the process you may be able to figure out the solution yourself.

Alas, display_draw presented looks like a meaningless babble. Your matrix row has six elements, not 12. Why i < mega[12] ? The 1st index of an array parameter has max value 11, mega[i] is int* pointer to i-th row of matrix - and so on...

Of course, the code below is not a masterpiece of C++ style but it works:

void display_draw(int mega[12][6], int draw_index);  

int HelpMe()  
{  
    const int NUMROWS = 12;  
    const int NUMCOLS = 6;  
    int draw_index;  
    int val[NUMROWS][NUMCOLS] =
   { 
        { 5,14,16,39,51,34 },  
        { 1,20,22,29,41,35 },  
        { 1,3,12,19,20,28   },  
        { 1,22,33,43,52,36 },  
        { 8,14,22,39,50,44 },  
        { 10,22,36,50,53,39 },  
        { 11,17,25,36,42,13 },  
        { 5,14,25,47,49,36 },  
        { 8,9,14,38,44,36 },  
        { 3,5,15,43,51,11 },  
        { 8,9,43,44,54,27 },  
        { 4,19,24,32,54,5 }, // optional last comma
   };  

    cout << "Please type in row number to print [0..11]: ";  
    if (cin >> draw_index)
   {
       if (draw_index >= 0 && draw_index < 12)
          display_draw(val,draw_index);
       else
          cout << "Index is out of range 0..11" << endl;
   }
   return 0;  
}  

/// Print mega[draw_index] row
void display_draw(int mega[12][6], int draw_index)  
{
    for (int j = 0; j < 6; j++)
    {
        if (j) // print TAB before value (except on the start of line)
          cout << '\t';
        cout << mega[draw_index][j];
    }
    cout << endl; // push printed line
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.