Why am I getting errors saying "Unused Parameter n"?

436 views Asked by At

I have been trying to solve this cs50 pset3. I wrote this linear search algorithm and when I try to run it I get error saying "Unused parameter n", "Unused parameter values". Can anyone please tell me why am I getting this error. I tried re-arranging my code several times. Thank you,

bool linear_search(int value, int values[], int n)
{
    if (n < 1)  //if n is negative it has to return false.
    {
        return false;
    }

    bool result = false;

    for (int i = 0; i < n; i++)
    {
        if (values[i] == value)
        {
            result = true;
        }
        return result;
    }
    return false;    //it returns false if the value is not in values.
}
1

There are 1 answers

1
t.m. On

As you stated at the comments, the n that causes error is a parameter of another function

void sort(int values[], int n)

This is another function you have to implement in that HW. You can temporarily use n like n = n+1; in that function until you implement it.

The reason you get this as an error instead of warning is -Werror flag you using with clang (see the Makefile). This tells clang to treat warnings as errors so you will be forced to correct them before you can execute the program and probably submit the homework.