| | |
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:
Solved Threads: 0
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
code below will return index of the first target found.... how do i finish searching the whole array and display them? thank you
cpp Syntax (Toggle Plain Text)
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?
C++ Syntax (Toggle Plain Text)
int index = searchLN( <parameters here > ); while( inName[index].getlastname() == targetLastName) { cout << inName[index].getlastname() << " "; index++; }
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.
![]() |
Similar Threads
- why return an int from main? (C++)
- Return Array from C++ (C++)
- Can a function return 2 values? (C)
- int main() or void main() ??!! (C++)
- Type mismatch: cannot convert from int to ResultSet (JSP)
- Return variable (C++)
- Write sentence, then return # of vowels - Need help, plz. (C++)
Other Threads in the C++ Forum
- Previous Thread: No window.h
- Next Thread: errors in code
| Thread Tools | Search this Thread |
api application array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






