i have a 2D array of emp[20][10]

How can i do it such that it only prints out the selected index like emp[0][0] to emp[0][10] etc.

It will print around more than the selected..

for(int i= 0; i < 20; i++) 
{
    for (int j = 0; j < 10; j++) 
    {
        emp[0][j].viewEMP();
    }
}

Recommended Answers

All 3 Replies

i have a 2D array of emp[20][10]

How can i do it such that it only prints out the selected index like emp[0][0] to emp[0][10] etc.

It will print around more than the selected..

for(int i= 0; i < 20; i++) 
{
    for (int j = 0; j < 10; j++) 
    {
        emp[0][j].viewEMP();
    }
}

well, for [0][0] to [0][9] (bear in mind that arrays start at 0) you would just have the one loop:

for( int i = 0; i < 10; i++ ){
	emp[0][i].viewEMP();
}

Sean

so it is possible to remove for line 3 from my post => (int i= 0; i < 20; i++)

I need to code it in a view function
May i know what parameter to pass in ?

void Display(Employee emp, int size, int index)
{
          for( int i = 0; i < size; i++ ){
	emp[index][i].viewEMP();

}

Well, I'm not sure what the array has in it. or what the application is doing, but given the function, yes. You left out a closing brace at the end of the for loop. This actually is C stuff, not C++, so you might want to post there for matters like this.

Thanx...
Sean

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.