0

I am working at pset3 find - helpers.h. The file compiles but I the command line is yelling at me: enter image description here

I was searching the web for hours but cannot find the reason for these errors. Help is much appreciated. Thank you!

/** * helpers.h * * Helper functions for Problem Set 3. */

include

/** * Returns true if value is in array of n values, else false. */

bool search(int value, int values[], int n);

// BINARY search function.

int left; int mid; int right;

{ if (n <= 0) { return false; }

// value is in values -> true
do
{
    // look at middle of list
    right = n - 1;
    mid = 1 + right / 2;

    if (values[mid] == value)
    {
        return true;
    }

    // search left
    else if (values[mid] > value)
    {
        right = mid - 1;
    }

    // search right
    else if (values[mid] < value)
    {
        left = mid + 1;
    }

    n++;

}
while (left + 1 < right);

// value is not in values -> false.
return false;

}

/** * Sorts array of n values. */ void sort(int values[], int n);

int i; int min; int j; int temp;

{ for (i = 0; i < n - 2; i++) { // define minimum at first element. min = i;

    for (j = i + 1; j < n; j++)
    {
        if (values[min] > values[j])
        {
            min = j;
        }
    }

    // swapping of values.
    if (min != i)
    {
        int temp = values[min];
        values[min] = values[i];
        values[i] = temp;
    }

}

}

1 Answer 1

1

Be sure that you put the body of the function inside of curly braces. You currently have

bool search(int value, int values[], int n);

that semicolon at the end means "this is the end".

You should have:

bool search(int value, int values[], int n)
{
       // all the code
}

and same for the sort.

You must log in to answer this question.

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