[Note: This is a homework assignment. Just guidance on where my code is flawed and/or thoughts/suggestions/tips/etc. Thank you!]
I am having issues getting my search of an array to properly process within my function. (The assignment is to use a function to search an array.) The search feature works outside of the function, but not within. All the other sequences within the program work exactly the way I desire them to as well. Any help that can point me in the right direction to helping resolve this would be greatly appreciated!
Here's just the code I'm having issues with. It points back to two paralell user-defined arrays, 10 items per array. I can display them, just not search them. I'm using a looping menu, and when the user enters the menu option, the code returns:
Please enter a name to search for: .Your search for was not found.
(Followed by my menu prompt, which is the only thing it does properly.)
It would appear that you are searching for an empty string.
Line 6, getline(cin, soughtValue);
if the input buffer starts with a new line, the string that is read would be an empty string.
If that is the case, we need to extract and discard leading white space characters in the input buffer before attempting to read the string. For instance: getline( cin >> std::ws, soughtValue );
In any case, print out a message immediately after the line which would help in understanding what is going on: std::cout << "searching for name '" << soughtValue << "'\n" ;
Also, make the function const-correct: void searchTel( const long long telNo[], const string name[], int numElem )
Thank you both so much! I implemented some of the steps you suggested - the break in the loop, and clearing the whitespace - and that seems to have done the trick! Thank you!!