Search function with arrays

string namesAr[] is a array of names

my complier error is that == is invalid.

searchItem is char. using a getline to retrieve it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int SearchFunction (string namesAr[], int idsAr[], float balanceDueAr[],int
                   AR_SIZEFUN, char searchItem)
{
	int index = 0;
	bool found = false;

	while (index < AR_SIZEFUN && !found)
	{
		if(namesAr[index] == searchItem)
		{
			found = true;
		}
		else
			index++;
	}
return(index);
'searchItem' should probably be a string.

As it is now, you're comparing a string to a single character. Is this really what you want to do?
im trying to search for names, like from a list. they enter Joe and we say Joe was found.
Right

"Joe" is a string, not a char. 'J' would be a char. You don't want to search for 'J'

searchItem should be a string.
Thanks, fixed that problem.
Topic archived. No new replies allowed.