text: Q:
  
  Guess my number c++ while loop inside a loop
  
  I have this simple guess my number code as I am learning C++. As you can see it selects a random number and lets the user guess it and records the number of tries.
  int main(){
     srand(static_cast<unsigned int>(time(0))); // seed number generator
  
     int secretNumber = rand() % 100 + 1;
     int tries = 0;
     int guess;
  
     cout << "\tWelcome to Guess my Number\n\n";
     do{
      cout << "Enter a guess: ";
      cin >> guess;
      ++tries;
  
      if (guess > secretNumber){
          cout << "Too high\n";
      } else if (guess < secretNumber){
          cout << "Too low \n";
      } else {
          cout << "You got it :) in " << tries << " tries \n\n";
      }
     } while(guess != secretNumber);
  }
  
  While this is working correctly, I also want user to have only 5 tries. I can think of adding another else if statement to ensure that (tries < 6).
  OR
  I can create another while loop inside do and ensure that (tries < 6). 
  What would be the best approach here?
  
  A:
  
  you can add a condition to your do-while-loop
  int main(){
     srand(static_cast<unsigned int>(time(0))); // seed number generator
  
     int secretNumber = rand() % 100 + 1;
     int tries = 0;
     int guess;
  
     cout << "\tWelcome to Guess my Number\n\n";
     do{
      cout << "Enter a guess: ";
      cin >> guess;
      ++tries;
  
      if (guess > secretNumber){
          cout << "Too high\n";
      } else if (guess < secretNumber){
          cout << "Too low \n";
      } else {
          cout << "You got it :) in " << tries << " tries \n\n";
      }
     } while((guess != secretNumber) && (tries < 6));
  }
  
  