im trying to write a code that should allow me to search a string of array that i enter when prompt. the program ask the uses to enter certain amount or data and then asks the use to perform a search. im having a hard time search for the input. i can do this with integers but now string please help. how would you do this.
#include <iostream>
using namespace std;
void contactArray(string a[], int size);
string search(const string a[], int size, string find);
int main( )
{
cout << "This program searches a list .\n";
const int arraySize = 3;
string a[arraySize];
contactArray(a, arraySize);
string find;
cout << "Enter a value to search for: ";
cin >> find;
string lookup = search(a, arraySize, find);
if (lookup == " ")
cout << find << " is not in the array.\n";
else
cout << find << " is element " << lookup << " in the array.\n";
return 0;
}
void contactArray(string a[], int size)
{
cout << "Enter " << size << " list.\n";
for (int index = 0; index < size; index++)
cin >> a[index];
}
int search(const string a[], int size, string find)
{
string index = "";
while ((a[index[3]] != find) && (index < size))
cout<<"try again"<<endl;
if (index == find)
index = "";
return index;
cout<<"hgi";
}
You can do it with integers? Do it with integers, call that function with strings, and wherever you get a
cannot convert string to intcompiler error, change the wordinttostring. It should be almost exactly the same.