so ive cleaned up my code but it still always prints 'found needle in haystack'! please help!
/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{
//ensures that values are entered
if (n < 0)
{
printf("n must be a non-negative integer\n");
return false;
}
//iterates through 'haystack'
else
{
for (int i = 0; i < n; i++)
//finds midpoint position of array sized 'n'
{
int middlevalue = values[(n+1)/2];
//if the midpoint value is the 'needle' returns true
if (middlevalue == value)
{
return true;
}
}
}
//searches right side of array for 'needle'
int middlevalue = values[(n+1)/2];
if (value > middlevalue)
{
for (int i = 0; (middlevalue < i < n); i++)
{
if (i == value)
{
return true;
}
}
}
//searches left side of array
else if (value < middlevalue)
{
for (int i = 0; (0 < i < middlevalue); i++)
{
if (i == value)
{
return true;
}
}
}
return false;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
//for array of size 'n' pass through the array n-1 times
for (int h = 0; h < n; h++)
{
//for each element in the array (with each 'h' iteration, does not check last 'i' elements)
for (int i = 0; i < (n-h); i++)
{
//if the element is bigger than the subsequent one
if (values[i] > values[i+1])
{
//i+1 swaps with i
int j = (i+1); //i+1 stored as j
i = i+1; //i stored as i+1
i = j; //j stored as i
}
}
}
}