is it possible to return more than one int?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

is it possible to return more than one int?

 
0
  #1
Feb 5th, 2008
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

  1.  
  2. int searchLN(Name *inName[], string targetLastName, int j)
  3. {
  4. int index=0;
  5. bool found = false;
  6.  
  7. while( (!found)&& (index<j) )
  8. {
  9. if((*inName[index]).getLastName()== targetID)
  10. {
  11. found= true;
  12.  
  13. }
  14.  
  15. else
  16. {
  17. index++;
  18. }
  19. }
  20.  
  21. if(found)
  22. return index;
  23.  
  24. else
  25. return -1;
  26. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: is it possible to return more than one int?

 
0
  #2
Feb 5th, 2008
why can't the calling function check to see if there are more last names with the same value?
  1. int index = searchLN( <parameters here > );
  2. while( inName[index].getlastname() == targetLastName)
  3. {
  4. cout << inName[index].getlastname() << " ";
  5. index++;
  6. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC