I am trying a number guessing game that I found, it seems that no matter what I choose, it keeps saying the number I've chosen is less than, or more than. I want to implement it using binary search, but have no idea how to do this. How can I make it happen?
Codes:
#include <cstdlib>
#include <time.h>
#include <iostream>
using namespace std;
int main() {
srand(time(0));
int number;
number = rand() % 100 + 1;
int guess;
do {
cout << "Enter a number of your choice b/w 1-100: ";
cin >> guess;
if (guess < number)
cout << "Sorry, try again, it's smaller than the secret number!" << endl;
else if (guess > number)
cout << "Sorry, try again, it's bigger than the secret number!" << endl;
else
cout << "The number is correct! Congratulations!" << endl;
} while (guess != number);
system("PAUSE");
return 0;
}