HI, everyone. I am having trouble getting the index of the location of the search number to print out. This is my program. Any help would be greatly appreciated!
#include<iostream.h>
#include<cmath>
void sortit(int x[], int n)
{
int temp,i,j;
for(i=0;i<n;i++)
for(j=i;j<n;j++)
if(x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
void bsearch(int x[], int max, int searchnum)
{
int mid;
int high=0;
int size;
int low = size-1;
int location = -1;
int found;
while(high <=low && found==false)
{
mid=(high + low)/2;
if(x[mid]==searchnum)
location=mid;
found=true;
else if(searchnum>>x[mid])
high=(mid + 1);
else
low= (mid - 1);
}
}
main()
{
int num[11];
int max=10;
int i,mid,x,location;
int searchnum;
int found;
for(i=0;i<11;i++)
{
cin>>num[i]; //
}
sortit(num,max);
cout<<"The list sorted is: "<<endl;
for(int i=0;i<max;i++)
cout<<num[i]<<"\n";
while(cin>>searchnum)
{
bsearch(num,max,searchnum);
}
cout<<"The number is " <<searchnum<<endl;
if(found=true)
cout<<"The number was found at location" <<location<<endl;
else cout<<"Number not found" <<"\n";
}
PLEASE FEEL FREE TO MAKE ANY CORRECTIONS IF NEEDED