Cannot find the position of an element inside a descending order array using binary search.
Here is the code: #define n 9 bool found = false; int binarysearch(int array[n],int element){ int start = 0; int end = n-1; int mid; while(start<=end && !(found)){ mid = start + end / 2; if(element==array[mid]) found=true; else if(element<array[mid]) { start = mid + 1; else end = mid - 1; } if(found) return mid; else return -1; } int main (){ int array[n]={10,9,8,7,6,5,4,3,2}; cout << "Enter the element you want to find the position in the array " << endl; int x; cin >> x; int index = binarysearch(array,x); if(index!=-1) cout << index << endl; else cout << "index not found"<<endl } The logic is i think okay but i guess sth is wrong with the code since it doesnt return the index or the position of a given element. Any advice would be appreciated!