Start New Discussion within our Software Development Community

I am trying to search an array of object, for example lastName, a private variable of the object, however, the array might have more than one same last name from different objects.. i need to output all the same last name onto the screen, how should i do that?

code below will return index of the first target found.... how do i finish searching the whole array and display them? thank you

int searchLN(Name *inName[], string targetLastName, int j)
		{
			int index=0;
			bool found = false;

			while( (!found)&& (index<j) )
			{
				if((*inName[index]).getLastName()== targetID)
				{
					found= true;
					
				}

				else
				{
					index++;
				}
			}

			if(found)
				return index;

			else
				return -1;
		}

why can't the calling function check to see if there are more last names with the same value?

int index = searchLN( <parameters here > );
while( inName[index].getlastname() == targetLastName)
{
    cout << inName[index].getlastname() << " ";
    index++;
}
This question has already been answered. Start a new discussion instead.