Your for loop that begins on line 59 will never repeat. This function will either return nothing, resulting in undefined behavior when you use the result it didn't return or return -1. There is no other possibility given the logic in the function.
If the first if-condition is false, the function will immediately return -1 in the first iteration of the loop.
If the first if-condition happens to be true on the first iteration, then 'which' is assigned true, and the break statement that follows will break you out of the for-loop. Thus, the return statement on line 66 will never be executed.
Try this:
1 2 3 4 5 6 7 8 9 10 11 12
int choice(listOfNumbers& p, int numberChoice) {
int i;
for (i = 0; i < p.arrayLength; i++) {
if (p.array[i] == numberChoice) {
return i; // if number found, simply return index
}
}
return -1; // if we made it outside of the loop, number was never found, so return -1.
}
I see. I've got to work on thinking logically. I seem to make logic mistakes more than syntax. I guess that's just natural to make these mistakes.
Thanks dudes!