Your code inside the
for
loop is chaotic at best and doesn't need the
else
clause of the
if
statement. Your function doesn't return a value on all code paths. What happens if the loop completes without satisfying any of the conditions you set in those
if
statements? The compiler cannot figure that out and cannot assume the
for
loop will never complete.
You should be rewriting this code to set a return value instead of just straight out returning from inside the loop. For example:
bool search(int value, int values[], int n)
{
bool returnValue = false;
if ( n >= 0)
{
for (int a = 0; a < n; a++)
{
if (values[a] == value)
{
returnValue = true;
break;
}
}
}
return returnValue;
}