Hello, I am trying to use the following function to search an array of structs, however it doesn't seem to be working and it is returning the same thing no matter what I search... which is 15.
I am trying to return the number of the value of the array while searching for the name of the item.
1 2 3 4 5 6
int search(Tools inventory[], string name, int length) {
int loc = -1;
for (int i = 0; i < length && loc != -1; i++)
if (inventory[i].name == name)
loc = i;
return loc;
int loc = -1;;//this is your error
for (int i = 0; i < length && loc != -1; i++);// terminates because loc == -1
if (inventory[i].name == name)
loc = i;