title: CS50 Pset 3 Finding the Needle
body: <p>I realised that when I included the "else return false" in my bool search, it will never be able to "find the needle". Conversely, if I were to remove that part, the program works fine. It is able to find 2008 and not find 2013. Any idea why is this so?</p>
  
  <pre><code> /**
   * helpers.c
   *
   * Computer Science 50
   * Problem Set 3
   *
   * Helper functions for Problem Set 3.
   */
  
  #include &lt;cs50.h&gt;
  
  #include "helpers.h"
  
  /**
   * Returns true if value is in array of n values, else false.
   */
  
   //value = needle , values[] = haystack, n = size
  bool search(int value, int values[], int n)
  {
      // TODO: implement a searching algorithm
      if(n&lt;0)    
      return false;
  
  
      for(int i=0;i&lt;n;i++)
      {
          if(value == values[i]) 
          {           
              return true;
          }
  
          else
          {
              return false;
          }
  
  
      }
      return false;
  }
  
  /**
   * Sorts array of n values.
   */
  void sort(int values[], int n)
  {
      // TODO: implement an O(n^2) sorting algorithm
      return;
  }
  </code></pre>