Please note, an ordered array is a precondition of the binary search.
To fix your code you might write:
#include <iostream>
#include <algorithm>
bool search(int a[], size_t size, int item)
{
int beg = 0;
int end = size-1;
while (true)
{
if ( (beg + 1) >= end)
return (item == a[end] || item ==a[beg]);
int mid = (beg+end)/2;
if ( item == a[mid])
return true;
else if ( item < a[mid] )
end = mid;
else
beg = mid;
}
}
enum { max_size = 90 };
int main()
{
int a[max_size];
int item;
std::cout << "Enter the item to search for ";
std::cin >> item;
size_t size;
std::cout << "Enter the array size ";
std::cin >> size;
if ( size > max_size)
{
std::cerr << "wrong input\n";
return -1;
}
std::cout << "Enter the array elements\n";
for (size_t n = 0; n< size; ++n)
std::cin >> a[n];
std::sort( &a[0], &a[size]);
bool found = search( a, size, item);
std::cout << "The item is " << (found ? "found\n" : "not found\n");
}
However, in all programs but exercises, I would use the firepower of the standard C++ library:
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
int item;
std::cout << "Enter the item to search for ";
std::cin >> item;
size_t size;
std::cout << "Enter the array size ";
std::cin >> size;
std::cout << "Enter the array elements\n";
std::vector<int> v;
v.resize(size);
for (auto & x : v)
std::cin >> x;
sort(v.begin(), v.end());
auto found = binary_search(v.begin(), v.end(), item);
std::cout << "The item is " << (found ? "found\n" : "not found\n");
}