Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 118,923 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,947 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



display the row

 
Reply to this topicStart new topic

display the row, help with code

asad12
post 17 Jul, 2008 - 04:01 PM
Post #1


New D.I.C Head

*
Joined: 7 Jul, 2008
Posts: 4

i need to display the row;
i need suggestion how to do it, here' waht i have
CODE
#include<iostream>
#include<iomanip>
using namespace std;
void display_draw(int mega[12][6], int draw_index);
int main()

    
{
    int i=0,j;
    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};

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

    return;
    }
User is offlineProfile CardPM

Go to the top of the page


F!st!cuffs
post 17 Jul, 2008 - 06:00 PM
Post #2


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 40



Thanked 1 times
My Contributions


QUOTE(asad12 @ 17 Jul, 2008 - 04:01 PM) *


cpp
 #include<iostream>
#include<iomanip>
using namespace std;
void display_draw(int mega[12][6], int draw_index);
int main()


{
int i=0,j;
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};

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

return;
}




Firstly your declaring NUMROWS const so cin << NUMROWS[i]; on line 28 wont work.
it's also not an array so you should try just cin << i; or cin << draw_index; which is what you probably intended.

Secondly on line 29 your redeclaring val and draw_index so take out the int beforehand and replace draw_index with i or just draw_index because that is the row that the user wants to display.

Also in your display_draw definition your first parameter is mega yet you reference NUMROWS[i] which hasnt been declared.

Most of the errors here are pretty simple and could probably be found when you try to compile. If you didn't debug your compile errors and want to be a serious programmer then your gonna have to start doing it yourself. It comes with the territory

step 1: write code
step 2: compile code
step 3: fix errors
step 4 repeat steps 2-3 until program works

Good luck!
User is offlineProfile CardPM

Go to the top of the page

asad12
post 18 Jul, 2008 - 09:18 AM
Post #3


New D.I.C Head

*
Joined: 7 Jul, 2008
Posts: 4

i changed the main function , which has no errors, but the function still errors which i am kind a confuse ,
can't debug until the program is totally error free. Just give me sugggestiion, where i am wrong, so i can fix it ,

CODE
      #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;  
   }
User is offlineProfile CardPM

Go to the top of the page

F!st!cuffs
post 18 Jul, 2008 - 09:28 AM
Post #4


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 40



Thanked 1 times
My Contributions


You can debug your compile errors. Just follow the four steps I provided in my earlier post because this really is an essential part of programming and if you don't start now at the beginning then you'll make a horrible programmer.
User is offlineProfile CardPM

Go to the top of the page

asad12
post 19 Jul, 2008 - 06:52 PM
Post #5


New D.I.C Head

*
Joined: 7 Jul, 2008
Posts: 4

i have one error which i can't fix, please let me know how to fix it

CODE
c:\documents and settings\loin\my documents\visual studio 2008\projects\hh\hh.cpp(37) : error C2440: '=' : cannot convert from 'int' to 'int [6]'


CODE
     #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;  
   }
User is offlineProfile CardPM

Go to the top of the page

nirvanarupali
post 21 Jul, 2008 - 12:31 AM
Post #6


"To think is to create"

Group Icon
Joined: 1 Aug, 2007
Posts: 965



Thanked 2 times

Dream Kudos: 375
My Contributions


I have revised your codes. I eliminate the display_draw function. I'm not sure if this
what you want.

CODE
#include<iostream>  
using namespace std;  

int main()  
{  
        
       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};  
    
   int row, colum;
   cout<<"Number of rows"<<endl;  
   cin>>row;  
   cout<<"Number of columns"<<endl;  
   cin>>colum;
   //Display now.                            
   for(int i=0;i<row;i++)                
    {  
        for (int j=0; j<colum; j++)
        {
            cout << val[i][j]<<",";
        }
        cout <<"\n";
    }                          
                                
                                
    return 0;  
}  

First of all you cannot use the local variables from other function to another. Hence
you cannot use the val array to the display_draw function. Since you use mega array and this is empty
you get error of this.

If you want to use val array variable, then you need to move it within the display_draw function not in main function.

Other option:
CODE
#include<iostream>  
using namespace std;

//Display now.  
void display_draw(int row, int colum)
{
   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};
   for(int i=0;i<row;i++)                
    {  
        for (int j=0; j<colum; j++)
        {
            cout << val[i][j]<<",";
        }
        cout <<"\n";
    }
}    
//driver program
int main()  
{  
   int row, colum;
   cout<<"Number of rows"<<endl;  
   cin>>row;  
   cout<<"Number of columns"<<endl;  
   cin>>colum;
   display_draw(row, colum);
                  
                                
   return 0;  
}  


Enjoy!:)
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/13/08 05:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month