Skip to main content
1 of 2
Jere
  • 37
  • 8

working with pset3

why isnt the compiler returning the false if the needle is not in the haystack.This is my modified code with the SESE method.

/**

  • 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 int i, r;

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

/**

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

but it dosent return the false value.

Jere
  • 37
  • 8