So, my program picks randomly a number between [1, 100] and I'm trying to implement a binary search algorithm to find that number. The problem is, nothing happens when it compiles it only says: "-------------- Build: Debug in RandWithBinary (compiler: GNU GCC Compiler)---------------
Target is up to date.
Nothing to be done (all items are up-to-date)." I don't understand...
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int RandomNumber () //Computer selects a randomly a number within the interval
{
return rand() % 101 + 1;
}
int BinarySearch (int low, int high, int pick) // Algorithm function that finds the number
{
int guess = (high + low) / 2;
int n = 0;
while (guess != pick)
{
int guess = (high + low) / 2;
if(guess < pick)
{
low = guess + 1;
n = n + 1;
}
else if (guess > pick)
{
high = guess - 1;
n= n + 1;
}
else if (guess == pick)
{
n = n + 1;
return n;
break;
}
}
if (guess == pick)
{
n = n + 1;
return n;
}
}
int main()
{
srand(time(NULL));
int pick = RandomNumber();
int tries = BinarySearch(0, 100, pick);
cout << "For the randomly picked number" " " << pick << "in the [1, 100] interval, it took the binary search algorithm" " "<< tries << " " "tries. \n";
}