User guesses the number generated by computer This is my code, which chooses a random number from 0 to 10 for the user to guess.
//guess the number game
//my code
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;

using namespace std;

int main()
{
  unsigned int secretNumber; 
  int guess;
  int maxNumber = 10;
  int maxTries = 4;
  int numTries = 1;


  srand(static_cast&lt;unsigned int&gt;(time(0)));
  secretNumber = (rand() % 10)+ 1;
  cout &lt;&lt; &quot;GUESS A NUMBER FROM 0 TO 10!!\n&quot;;
    do {
      cout &lt;&lt; &quot;\nGuess: \n&quot;;
      cin &gt;&gt; guess;

      if (guess &lt; secretNumber)
      {
          cout &lt;&lt; &quot;too low:(:(!!      &quot;;
          numTries++;
          cout &lt;&lt; &quot;Guesses Left: &quot; &lt;&lt; maxTries - numTries;
      } ***//Would it be better to add a bool in the condition?***

      else if (guess &gt; secretNumber &amp;&amp; guess &lt;= maxNumber)
      {
          cout &lt;&lt; &quot;Too high:D:D!!      &quot;;
          numTries++;
          cout &lt;&lt; &quot;Guesses Left: &quot; &lt;&lt; maxTries - numTries;
      }

      else if (guess &gt; maxNumber)
      {
          cout &lt;&lt; &quot;Do you know how to count to 10?\n&quot;;
          cout &lt;&lt; &quot;Only from 0 TO 10!!  &quot;;
          numTries++;
          cout &lt;&lt; &quot;Guesses Left: &quot; &lt;&lt; maxTries - numTries;
      }

      else {
          cout &lt;&lt; &quot;WOW! you GUESSED IT?! AMAZING!!!!&quot;;
          cout &lt;&lt; &quot;You're right! the number is &quot; &lt;&lt; guess; 
          cout &lt;&lt; &quot;\nYou got it right in &quot; &lt;&lt; numTries &lt;&lt; &quot; guesses!!!&quot;;
      }

      if (numTries == maxTries)
      {
          cout &lt;&lt; &quot;\n\nYou LOOSE :( LOL!&quot;;
      }


  } while (guess != secretNumber &amp;&amp; maxTries != numTries);

  return 0;
} 

This is the teacher's code, which is simpler and includes a bool variable. Should my previous code be simpler, just as this one?
int main()
{
  int secretNumber = 7; 
  int guess;
  int numTries = 0;
  int maxTries = 3;
  bool outOfGuesses = false;

  while (secretNumber != guess &amp;&amp; !outOfGuesses)
  {
      if (numTries != maxTries)
      {cout &lt;&lt; &quot;Guess a Number: &quot;;
      cin &gt;&gt; guess;
      numTries++;}

      else 
      {
          outOfGuesses = true;
      }
  }

  if (outOfGuesses)
  {
      cout &lt;&lt; &quot;You loose!&quot;;
  }
  else 
  {
      cout &lt;&lt; &quot;You win!&quot;;
  }
  return 0;
}

Is my code as efficient and simple as the teacher's code? //Is there a simpler way to do what I intended to do in my code?
Preface
I'm going to ignore your teacher's code, at least for the moment, and just review yours.
Based on what you've said, I'm guessing you're still pretty close to the beginning of the learning curve. Based on that, I'm going to go into a little more detail that normal about how to move in a direction I think you'll find beneficial, rather than just talking about where you might like to end up.
Approach
First of all, you currently have all your code in main. It can be extremely helpful to define small, self-contained functions to carry out the overall task, instead of having it all inline in a single function like this.
To do this, I'd start with a really basic outline of what the program is supposed to do:

generate a random number
While they haven't used up their guesses or gotten the right answer:

get a guess at the random number from the user
check whether their guess is high, low, or correct

print out the result





Then I'd consider which of those is easily turned into a separate, self-contained piece of code (hint: most of them).
Then I'd write code in main that worked at pretty much that level, and have it delegate the details to other code. A first stab at it might look something like this:
int main() { 
    int secretNumber = generate_random();
    int maxTries = 3;

    for (int guessCount = 0; guessCount &lt; maxTries; guessCount++) {
        int guess = get_guess();
        if (check_guess(guess, secretNumber))
            break;
    }
}

Initially, I wouldn't worry a lot about getting every detail precisely correct. Just try to get something that fits reasonably well with the outline you write in English.
From there, you have a couple of choices. One is to start by writing &quot;mock&quot; versions of most of those. They need to do roughly the right sort of thing, but don't put any effort into really making them do the job correctly. For example, we can write a &quot;mock&quot; &quot;generate a random number&quot; as something like:
int generate_random() { 
    return 7;
}

That obviously won't do in the long term, but it's enough that we can use it to write and test the rest of the code. Then do roughly the same with the other functions:
bool check_guess(int guess, int secretNumber) {
    // Todo: add code to print out current result
    return guess == secretNumber;
}

int get_guess() { 
    static int guess;

    return guess++;
}

Now we have enough that we can test the basic flow of the program. For example, we can check that when we run it, it doesn't get stuck in a loop; it runs to termination. Once we've established that, we can add enough more to print out each guess, and whether it was right or wrong, and see that as-is, it guesses values for 0 through 10, then quits because it used up the allotted number of guesses. If so, great. If not, we figure out why not and fix that.
Then we change the random number to (say) 5, so it should guess correctly before it runs out of guesses. Then we run that to be sure it does what it should (like, print out the message that you got the right answer, and then quit asking for more guesses once 5 is guessed).
Once we're done verifying that the basic flow of the code in main works correctly, we can expand out those subordinate functions to do their jobs correctly, so generate_random() actually generates a random number, get_guess() really asks the user for input, and do on.
The important point here so to break the large, somewhat complex task down into a number of smaller tasks, each of which is quite simple. This way, it's much easier to define and understand what each piece needs to do, and test the code so we can be sure that it does what it's really supposed to.
Other Points
I think it's worth pointing out that I'm positively impressed with a number of things about your code. You've chosen good, clear variable names, and structured the code so it's really quite clean and understandable. It's longer than your teacher's, but length is rarely a good measure of much of anything, and its length doesn't seem (to me) particularly excessive for what it does. A fair amount of the extra length is simply because your teacher's code is closer to what I've recommended as the first step on the way toward better code--for example, it chooses the same &quot;random&quot; number every time it's run. That's simple and easy to test with, but yours is clearly a more complete program in this regard.
As far as the specific question of whether to use a Boolean variable: it doesn't strike me as necessary in this case, but it's also fairly harmless. I can see writing the code either with or without it, and doubt that either is necessarily much better than the other.