Question about find and helpers.c. When I run check50 on my code, I get the following error below:
:( doesn't find 42 in {39,40,41} \ expected an exit code of 1, not 0
:( doesn't find 42 in {39,40,41,43} \ expected an exit code of 1, not 0
I know that I should be returning 1 because 42 is indeed not in the list of numbers and I believe this relates to my binary search portion of my code but I can't figure out why it won't work. Any insight would be much appreciated. I did not modify find.c at all.
Here is the binary search algorithm I'm using:
> bool search(int value, int values[], int n) {
>
> int min = 0; int max = n-1;
>
> if (n <0)
> {
> return false;
> }
> while (max >= min)
> {
> int mid = (max+min)/2;
> if (mid == value)
> {
> return true;
> }
> else if (mid < value)
> {
> min = mid+1;
> }
> else if (mid > value)
> {
> max = mid-1;
> }
> return true;
> }
> return false; }