It's mostly a duplicate, but it bears repeating and could use a more specific answer here.
Your logic is right in that, assuming there are no issues with the data fed to it, the function will return a bool one way or another. The problem is that the compiler isn't smart enough to recognize the complexity of the logic.
So, the compiler looks at the structure of the code. It sees the if/else and decides that when the IF condition is false and the ELSE branch is taken, it sees a possible path where the FOR loop is not executed, so the code could reach the end without hitting a return.
So how do you fix this? It's fairly simple. Put a return statement before the closing } so that there is no possible way that the code can exit without hitting a return.
Now, having said that, the code does have some other structural issues.
First, the break will never execute. The line before is a return, so control will immediately exit the function at that point. The break can be deleted without problem.
for(int i=0; i<n;i++) will only execute the loop once because of the if/else combination. You will either execute the
return true or the
return false before the end of the first pass through the loop. It will never increment i. (If you added the break to avoid this, it won't work.)
Your code would be much cleaner if you did it without any ELSE clauses. (Keep the code, just get rid of the ELSE keyword.) Basically, if any of the code before the ELSE code blocks executes, it executes a return. IF it doesn't execute the return, normal processing will drop through to what is currently an ELSE clause anyways. Pseudocode:
if( n<1 ) return false; // actually, this is redundant too.
for(int i=0; i<n;i++) if ( found ) return true;
If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)