Hi all

Please help me to solve this problem. i tried to solve this problem many times. but i couldnt do that. so please look at my code & help me to code this correctly.

thanks

Write a C++ program that will call a function that performs Binary Search on a sorted array. [You could use the binary search function provided in the class notes for this task.] The value to be searched for is: 12.5

float array2 = { 2.3, 4.8, 5.1, 6.8, 7.6, 8.3, 10.2, 11.4, 12.5, 18.9, 27.3 }

The code need to correct

Please help me to solve this problem. i tried to solve this problem many times. but i couldnt do that. so please look at my code & help me to code this correctly.

thanks

Write a C++ program that will call a function that performs Binary Search on a sorted array. [You could use the binary search function provided in the class notes for this task.] The value to be searched for is: 12.5

float array2 = { 2.3, 4.8, 5.1, 6.8, 7.6, 8.3, 10.2, 11.4, 12.5, 18.9, 27.3 }

The code need to correct

**Code:**Code:

#include <iostream.h> #include <conio.h> int main() { float a[]={2.3,4.8,5.1,6.8,7.6,8.3,10.2,11.4,12.5,18.9,27.3}; float item=12.5; int middle; int lv=1,hv=11; for(int i=0;a[middle]!=item;i++) { middle = (lv + hv)/2; if(a[middle]>item) hv = middle - 1; else if(a[middle]<item) lv = middle + 1; else if(a[middle]==item) cout<<"Found your number in "<<middle+1<<" position."; } getch(); }

*Last edited by shabbir; 11Nov2008 at 10:23.. Reason: Code block*