Cannot figure out how to call a binsearch function Help

I want to call in a binsearch that searches through my function for a value typed in by the user but im not to sure if my function is set up correctly and how to call it when needed. Here is my code:


#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

void swap (int& x, int& y);
void selectionSort (int warehouse[], int len);
void binsearch (const int a[],int len, int item, int& index, bool& found);
void removeSorted (int warehouse[], int & len, int item);

int main()
{
const int SIZE = 20;
string city1 = "Chicago";
string city2 = "Miami";
int warehouse1[SIZE];
int warehouse2[SIZE];
int width = 15;
int product;
int len = 0;
int len2 = 0;
int i = 0;
int j = 0;

cout.setf (ios::fixed | ios::left);

ifstream chicago;
chicago.open("Warehouse1.txt");
chicago >> product;
while (!chicago.fail())
{
warehouse1[len]=product;
len++;
chicago >> product;

}
chicago.close();

selectionSort(warehouse1,len);

ifstream miami;
miami.open("Warehouse2.txt");
miami >> product;
while (!miami.fail())
{
warehouse2[len2]=product;
len2++;
miami >> product;

}
miami.close();

selectionSort(warehouse2,len2);

while (i < len || j < len2)
{
if(warehouse1[i] == warehouse2[j])
{
cout << warehouse1[i] << city1 << " " << city2 << endl;
i++; j++;
}
else if (warehouse1[i] < warehouse2[j])
{
cout << warehouse1[i] << city1 << endl; i++;
}
else if (warehouse2[j] < warehouse1[i])
{
cout << warehouse2[j] << city2 << endl; j++;
}
}

cout << endl;
cout << "Enter the product to purchase (-1 to quit) ";
binsearch(warehouse,len);
cin >> product;

//binsearch (warehouse,len,item,index,found);

{
cout << "Product " << product << " is shipped from Chicago" << endl;
}



system("pause");

}


void selectionSort (int warehouse[], int len)
{
int ct1;
int ct2;
int mindex;
for (ct1=0; ct1 < len-1; ct1++)
{
mindex = ct1;
for (ct2=ct1+1; ct2 < len; ct2++)
if (warehouse[ct2] < warehouse[mindex]) mindex = ct2;
swap(warehouse[mindex],warehouse[ct1]);
}
}

void swap (int& x, int& y)
{
int temp;
temp = x;
x = y;
y = temp;
}

void binsearch (const int a[],int len, int item, int& index, bool& found)
{
int first = 0;
int last =len-1;
found = false;
while (!found && last >= first)
{
index = (first + last)/2;
if (item == a[index]) found = true;
else if(item < a[index]) last = index -1;
else first = index + 1;
}
if (item > a[index]) index++;

}

void removeSorted (int warehouse[], int& len, int item)
{
int index;
bool found;
int ct;
binsearch (warehouse, len, item, index, found);
if(found)
{
for (ct = len-1; ct >=index; ct--)
warehouse[ct+1] = warehouse[ct];
len--;
}
}
Topic archived. No new replies allowed.