0
/**
 * 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
    {
       if (n <= 0)
        {
           return false;
        }
       else
        {

            for (int i= 0; i < n; i++ )
                {
                    if values[i]==value
                    {
                    return true;
                    }



                }
            return false;
        }

    }    
}

Why doesn't this code work? returns false always (checked value 127)..

1 Answer 1

1

Just found it: I had to "make find " before testing for value 127 (./generate 1000 50 | ./find 127) !!

1
  • of course I had to add the brackets after if....
    – Samir-B
    Sep 6, 2016 at 21:36

You must log in to answer this question.

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