General comments.
The program is getting too long/complex to keep all the code within main(). The program would be easier to read/understand if it used separate functions for each activity, e.g. allocate and fill array, sort array, linear search, binary search.
Next, arrays in C++must have a size which is a compile-time constant.
int array[N];
is not valid in standard C++ because the value of N is not known until run-time. An alternative is to use new/delete.
|
int * array = new int [N]; // allocate array
|
|
delete [] array; // de-allocate array when finished
|
Specific problems with linear search.
1. If the item is not found, this loop will never terminate:
1 2 3 4
|
while (array[inc] != search || inc == N)
{
inc++;
}
|
One or both conditions will always be true (assuming not found). The subscript inc will exceed the array size N.
This would be better:
|
while (array[inc] != search && inc < N)
|
2. On the other hand, if the item is found, then the surrounding loop will repeat forever
(assuming user didn't ask for -1 as search value).