Binary guess game in C++ This is a program in C++ that guesses a number given by the user. I have to do homework and there's my attempt to solve an exercise from the programming book. If you know what can be done better and how to make more beautiful my code, let know me.
#include &lt;iostream&gt;

int main() {
    std::cout &lt;&lt; &quot;Enter number from range 0 to 100: &quot;;
    int num;
    std::cin &gt;&gt; num;
    int guess = 50;
    bool lower = false;
    bool upper = false;
    int min = 0;
    int max = 100;
    while (guess != num) {
        if (num &lt; guess) {
            std::cout &lt;&lt; &quot;Is this number lower than &quot; &lt;&lt; guess &lt;&lt; &quot;? (0 - false, 1 - true)\n&quot;;
            std::cin &gt;&gt; lower;
            if (lower) {
                upper = false;
                max = guess;
            }
        } else if (num &gt; guess) {
            std::cout &lt;&lt; &quot;Is this number greater than &quot; &lt;&lt; guess &lt;&lt; &quot;? (0 - false, 1 - true)\n&quot;;
            std::cin &gt;&gt; upper;
            if (upper) {
                lower = false;
                min = guess;
            }
        } else {
            std::cout &lt;&lt; &quot;Let's guess, this number is equal to 50, isn't it?\n&quot;;
        }
        guess = (min+max)/2;
    }
    std::cout &lt;&lt; &quot;You entered a number &quot; &lt;&lt; guess &lt;&lt; &quot;, did I guess?\n&quot;;
    return 0;
}
Overview:
You need to concentrate on writing self-documenting code. This basically means using self-documenting variable names and writing functions that do specific obvious self-documented tasks.
int main(int argc, char* argv[])
{
     // Handle command line arguments.
     // Set appropriate variables.

     playGuessNumberGame();  // Pass parameters you extracted from
                             // command line or environment.
}

void playGame()
{
     int  hiddenNumber = getNumberFromPlayer();
     bool finished     = false;

     while(!finished) {
         int guess = getNumberFromPlayer();  // Or calculate guess ?
         printHint(hiddenNumber, guess);

         finished = guess == hiddenNumber;
     }
}


Another thing I would think about is storing state in an object that is updated. In this case you have the guess that is updated based on whether it was lower or higher. I would wrap this logic into an object that understands how to use this data:
class Guesser
{
     int   min;
     int   max;
     int   currentGuess;
     public:
         Guesser(): min(0), max(100), currentGuess(50) {}
         int getBestGuess() const {return currentGuess;}
         void updateGuess(bool toLow) {
             if (toLow) {
                 int newGuess = currentGuess + (max - currentGuess)/2;
                 min = currentGuess;
                 currentGuess = newGuess;
             }
             else {
                 int newGuess = min + (currentGuess - min)/2;
                 max = currentGuess;
                 currentGuess = newGuess;
             }
              
         }
};

This way you isolate the variables that are associated with guessing, so they are not accidentally modified by external code.
Issues
There seems to be an issue with your tests. You are both testing the actual value then asking for user input to confirm what you actually know.
    if (num &lt; guess) {
        // Why are you asking this question.
        // You already know that the num is less than guess.
        // Are you trying to automate the processes or trying to
        // get user input to direct the action?
        std::cout &lt;&lt; &quot;Is this number lower than &quot; &lt;&lt; guess &lt;&lt; &quot;? (0 - false, 1 - true)\n&quot;;
        std::cin &gt;&gt; lower;


        // We know it is lower.
        // but you only update things if the user confirms.
        // if you get it wrong does this upset the program?
        if (lower) {
            upper = false;
            max = guess;
        }

Code Review:
You don't check if the input is valid:
    int num;
    std::cin &gt;&gt; num;

When accepting user input, always validate that you got something valid. Otherwise you will end up with the application locking up or going into an infinite loop. In this case the stream simply sets itself as bad when invalid data is input, which can be detected with if ()
   if (std::cin &gt;&gt; num) {
        // Read worked we have a number in the variable.
   }

Note: This will validate things like 54XX as good, since the first part is a valid number.  You may want to check the whole line to make sure it is just a number:
bool getValidNumberFromUser(int&amp; num)
{
   std::string userInput;
   std::getline(std::cin, userInput);

   std::stringstream userInputStream(userInput);

   if (userInputStream &gt;&gt; num) {
        // Succesfully read a number.
        // but there should be no other trash on the line.
        // so let us validate that we got just a number.
        char garbage;
        if (userInputStream &gt;&gt; garbage) {
            // we got some garbage so there was an error on
            // user input. Lets return false from this function.
            return false;
        }
        // If we got here not garbage.
        return true;
   }
   // If we get here the user input did not even start with a number
   // So let us fail.
   return false;
}

bool isNumberOutOfRange(int number)
{
    return number &lt; 0 || number &gt; 100;
}


int getNumberFromPlayer()
{
    std::cout &lt;&lt; &quot;Enter number from 0 -&gt; 100\n&quot;;

    int playerNumber;
    while(!getValidNumberFromUser(playerNumber) || isNumberOutOfRange(playerNumber)) {
        std::cout &lt;&lt; &quot;You entered an invalid number. Try Again\n&quot;;
    }
    return playerNumber;
}