Question: C++ My code doesn't output what is required because my binary search numbers are too small. We are suppose to make the code be searched
C++
My code doesn't output what is required because my binary search numbers are too small. We are suppose to make the code be searched binarily 1000 times. Can anyone help me fix my errors?(exclude linear search. Only need binary search)
Note: The code is for a random number to be binary searched through so the required code is an example as long as it outputs something similar.
My Code:![#include #include #include #include using namespace std; int binarySearch (int [], const](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/03/65f006239a76e_1710229023877.jpg)
![int,const int ); int getRandomNumber (const int); void printArray(int [], const int);](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/03/65f0062226b74_1710229023348.jpg)

My output:
![L 400; int values[arraySize]; for (int i = 0; i < arraySize;](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/03/65f0061f133a8_1710229020691.jpg)
![i++) { values [1] =getRandomNumber (arraySize * 2); } I std::sort(values, values](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/03/65f006210b6c6_1710229022554.jpg)
Required output:

#include #include #include #include using namespace std; int binarySearch (int [], const int,const int ); int getRandomNumber (const int); void printArray(int [], const int); int main() { srand(time(NULL)); const int numSearches = 1000; const int arraySize L 400; int values[arraySize]; for (int i = 0; i < arraySize; i++) { values [1] =getRandomNumber (arraySize * 2); } I std::sort(values, values + arraySize); for (int i=0; i < numSearches; i++) { int target getRandomNumber (arraySize 2); int result = binarySearch (values, arraySize, target); if (result == -1) { cout < < "Target: < < target < < "not found in array using BINARY SEARCH." < < endl; } else { cout < < "Target: " < < target < < "found at index: al" < < result < < "1" < < endl;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
