0

Need some help please. I was doing this particular pset without knowing what's wrong with the code. It doesn't pass check50. Thank you in advance.

enter image description here

And here's 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)
{

int lower = 0;
int upper = n - 1;

while (lower <= upper)
{
   int middle = (upper + lower) / 2;

   if (values[middle] == value)
   {
      return true;
   }
   else if (value[middle] < value)
   {
      lower = middle + 1;
   }
   else if (value[middle] > value)
   {
      upper = middle - 1;   
   }
} 

return false;
}

/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
for(int k = 0; k < n - 1; k++)
{
    int swaps = 0;

        for(int i = 0; i < n - 1 -k; i++)
        {
            if (values[i] > values[i+1])
            {
                int temp = values[i+1]);
                values[i+1] = values[i];
                values[i] = temp;
                swaps++;
            }
        }
if (!swaps)
    break;

}

return 0;
}
0

Very simply, your program doesn't compile. If it has compiler errors, it's premature to try and run check50 on it. You need to spend time fixing the compiler errors and then testing the code to make sure it executes correctly.

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

You must log in to answer this question.

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