0

Can anybody say what should i write in the last "return"? Cause if i try to compile my program i have this error: " helpers.c:50:5: error: void function 'sort' should not return a value [-Wreturn-type] return false; ^ ~~~~~ 1 error generated."

Here is my code:

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

include

include

include "helpers.h"

/**

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

bool search(int value, int values[], int n)
{
if(n>=0)
{
    for(int i=0;i<n;i++)
    {
        if (values[i]==value)
        {
            return true;
        }
        else
        {
           return false;  
        }
    }
}
return false;
}

/**Sorts array of n values.

void sort(int values[], int n)
{
int min;
for(int j=0;j<n-1;j++)
{
   for (int i=0;i<n;i++)
   {
       if (values[i]>values[i+1])
       {
       min=values[i+1];
       values[i+1]=values[i];
       values[i]=min;
       }
   }
}
return false;
}
1

You have a function that has a return type of void, meaning it should not return any values. return false; actually returns a value, a boolean value of false. Instead, you should simply have a return; statement with no value.

As for your search function, it has a different problem. It will never check more than one value in the array, but I'll let you sort that one out on your own. ;-)

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

| improve this answer | |

You must log in to answer this question.

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