I do not understand why I get an errors:
error: expected ';' after expression else (value > values[l])
and
helpers.c:40:21: error: expression result unused [-Werror,-Wunused-value] else (value > values[l])
on my code of binary search:
Returns true if value is in array of n values, else false. */ bool search(int value, int values[], int n) { // ensures that the n is non negative if (n < 1) return false; else { //making ints for binary searching: m - far right; k - far right ; l - middle/avarage of m and k; int m = 0; int k = n; int l = (m + k) / 2; do {
if (l == 0)
return false;
else if (l == value)
return true;
else if (value < values[l])
l = (m + (l - 1)) / 2;
else (value > values[l])
l = ((m + 1) + k) / 2;
}while (value != values[l])
}
the errors if for else but to be honest I do not see the difference between else if and else. Can somebody explain it to me? Thanks.