0

I have an issue with my helpers file.

I have tested the code using my own input of numbers using find.c

But when i use check50 on helpers.c i get this error:

:) helpers.c exists
:) helpers.c compiles
:( finds 42 in {42,43,44}
   \ expected an exit code of 0, not 1
:( finds 42 in {41,42,43}
   \ expected an exit code of 0, not 1
:( finds 42 in {40,41,42}
   \ expected an exit code of 0, not 1
:( finds 42 in {41,42,43,44}
   \ killed by server
:( finds 42 in {40,41,42,43}
   \ killed by server
:( finds 42 in {39,40,41,42}
   \ killed by server
:) doesn't find 42 in {39,40,41}
:( doesn't find 42 in {39,40,41,43}

It doesn't seem to make much sense why this would fail but using find works every time =/ Does gradebook simply rely on check50 to mark you or is there a human check to ? If they check it manually i should do fine but if they rely on check50 that is a problem =/

My search function:

bool search(int value, int values[], int n)
{
    if(n < 1)
    {
        return false;
    }

    int middlePoint = ceil(n/2);
    bool found      = false;

    while(middlePoint > 1)
    {
        if(value < values[middlePoint])
        {
            middlePoint = middlePoint - ceil(middlePoint/2); 
        }
        else if(value > values[middlePoint])
        {
            middlePoint = middlePoint + ceil(middlePoint/2);  
        }
        else
        {
            found = true;
        }
    }
    return found;
}
9
  • Do you return 1 in any case and especially when you find the number? You should return true if found and return false otherwise. – ChrisG Aug 5 '15 at 20:21
  • Do you mean in the sort function in helpers.c or in find.c? Because check50 seems to use helpers.c not find.c And the sort function doens't return a value as it is void(){} – user7869 Aug 5 '15 at 20:24
  • I mean in helpers.c in function search() – ChrisG Aug 5 '15 at 20:29
  • @ChrisGantidis should i add my search function in the question to help find the problem ? – user7869 Aug 5 '15 at 20:29
  • Yes you could if you like. – ChrisG Aug 5 '15 at 20:31
0

For start consider the first case that fails. If for example the number is in the first place which is values[0]. Your code will work as long as middlepoint is larger than 1, so it will never look at 0.

You must log in to answer this question.

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