title: While loops with timer in c++
body: <p>I'm trying to create a while loop that when either the string condition or the timer condition is met, the program will break out of the loop and print out the desired output. And when printing out the desired output, the output will contain the time difference from before and after comparing the answer.</p>
  
  <p>But the loop doesn't run the way i expects it to. So can anyone help me figure out where is the problem with this piece of code?</p>
  
  <p>Below is my code:</p>
  
  <pre><code>void startGame(time_t cd,int gl){
      string guessWord;
      time_t start, end, diff,timeLeft;
  
      cout &lt;&lt; "Scrambled word is " &lt;&lt; randomizeWord(gl) &lt;&lt; endl;
  
      while (timeLeft != cd || guessWord.compare(originalWord) == 0)
      {
          start = time(0);
          cout &lt;&lt; "You have " &lt;&lt; cd &lt;&lt; " seconds to guess." &lt;&lt; endl;
          cout &lt;&lt; "Enter guess : ";
          cin &gt;&gt; guessWord;
          end = time(0);
          diff = end - start;
          //total_time = total_time + diff;
          timeLeft = cd - diff;
  
          if(guessWord.compare(originalWord) != 0)
          {
              cout &lt;&lt; "WRONG! Attempt ... You have " &lt;&lt; timeLeft &lt;&lt; "seconds left... Try Again" &lt;&lt; endl;
              cout &lt;&lt; "Enter guess : ";
              cin &gt;&gt; guessWord;             
          }
          else
          {
              cout &lt;&lt; "You are CORRECT! "&lt;&lt; timeLeft &lt;&lt;" seconds left. Your timing is "&lt;&lt; diff &lt;&lt;" seconds." &lt;&lt; endl;            
              break;
          }
      }
  }
  </code></pre>