# Pset3 helpers.c only getting half the score

I have finished my helpers.c and handed it in thinking that it was good to go. When I execute it with find and generate like what was said in the lecture, it works perfectly fine. However, in my scoring card, it shows this:

Would anyone happens to know what's wrong with my code?

/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/

#include <cs50.h>

#include "helpers.h"

/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{
// TODO: implement a searching algorithm

for (int i = 0; i < n; i++)
{

if (values[i] == value)

{
return true;
break;
}

}
return false;
}

/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
// TODO: implement an O(n^2) sorting algorithm

int j;
int p;

for (int a = 0; a < n-1; a++)
{
int min= values [a];

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

}
if (min != values [a])

p = values [a];
values [a] = values [j];
values [j] = p;
}

return ;
}


Thanks!

Simply put, your sort() function is broken. If you want to see, add the following line to the end of the sort function before the return:

for(int x=0; x<n; x++) printf("values[%i] = %i \n",x, values[x]);


For starters, you're missing a set of curly braces, something you can find easily enough. Even then, there are flaws in your sort. Another indicator that something is amiss is that check50 is timing out when executed locally. Time to spend some quality time debugging.

BTW, the break; that follows the return is dead code (code that never executes). A return will immediately terminate processing of the current function and return control to the calling function, program, or operating system, so the flow of execution will never get to the break.

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

• Thanks Clff!!! :) – Leon Dec 12 '15 at 16:45
• Found it, it's my for loop! – Leon Dec 12 '15 at 17:11