ok for school im literally copy and pasting the binary search algorithm he gave us and apparently went i showed him my flowchart before i coded this program we musta missed something because it always returns a -1 and its due tommorrow and since i copy and pasted the algorithm well just used the already made one i have NO CLUE why its not working since it matches the flowchart just beautiful at least im not noticing an error

anyway why does it always return -1

Code:int bin_search(int id[],int elementsize,int user_id) { cout <<"BEGIINUIG"; int first = 0; int last = elementsize -1; int found = 0; int mid; while(first <= last && found == 0) { mid = (first + last) / 2; if(id[mid] == user_id) found = 1; else { if(id[mid] < user_id) last = mid - 1; else first = mid + 1; } } if(found == 0) { cout << "ALMOST THERE"; mid = -1; } cout << "ENDING"; return mid; }