0

I am not sure where I have gone wrong with helpers.c. I passed all check50 tests except for 2 under "doesn't find". My code is below:

code removed

What check50 returns is as follow:

:) helpers.c exists.
:) helpers.c compiles.
:) finds 28 in {28,29,30}
:) finds 28 in {27,28,29}
:) finds 28 in {26,27,28}
:) finds 28 in {27,28,29,30}
:) finds 28 in {26,27,28,29}
:) finds 28 in {25,26,27,28}
:( doesn't find 28 in {25,26,27}
    expected exit code 1, not 0
:( doesn't find 28 in {25,26,27,29}
    expected exit code 1, not 0
:) finds 28 in {30,27,28,26}

Any help will be greatly appreciated!

EDIT: false positive due to return true statement at the end of each if/else if statement. But "return true" statement should only be included after search() checks that target== mid ie the end of the implementation (the point of a function that returns a boolean). Also, setting up a variable to check the array index is key to solving this pset (at least for me).

1

Actually, the code is failing every test, but check50 doesn't see it. The problem is that the search function will return true 100% of the time, no matter what.

The problem lies in the while loop. In the first test, if mid == target, it will correctly return true. BUT, in the following two if statements, if mid is > or < target, it will also return true.

Simply put, on the first pass through the while loop, search is guaranteed to return true. This also means that any test that is finding the target is likely a false positive because it likely never actually found the target. It simply returned true.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .