I am working on an assignment that allows the program to ask the user to input a name in the last name "comma" first name format, (e.g. "Collins, Bill"). The input is then searched a pre-defined array. So, first I'm trying to sort the array, and then include the search function (search using binary search). After I coded it, it never finds the names that I have in the array and always says that the name was not found. Please help me! The code is below:
//Sorting the names in alphabetical order
sortNames(name, SIZE);
//Get user input for name
cout << "Enter the name you wish to find: ";
cin >> NameSearch;
cout << endl;
name_search = binaryNameSearch(name, SIZE, NameSearch);
if (name_search = -1)
{
cout << "The name you searched for does not exist. ";
}
else
{
cout << "You searched for " << NameSearch << ", and it was found in ";
cout << "the array.\n\n";
}
Hi,
Few changes:
1)
Instead of using >> use getline to enter name i.e.
replace cin >> NameSearch;
by getline(cin,NameSearch);
2)Function binaryNameSearch should return a value.
3)One silly error:
1 2
name_search = binaryNameSearch(name, SIZE, NameSearch);
if (name_search = -1)