title: Reset timer each iteration of a loop
body: <p>My intention is to create a program which analyzes different numbers of samples and every sample has a time limit. So the timer must reset for every sample. As well, must be a while loop which makes sure the program doesn't run for too long. </p>
  
  <p>Code: </p>
  
  <pre><code> #include &lt;cstdlib&gt;
   #include&lt;stdio.h&gt;
   #include &lt;iostream&gt;
   #include &lt;vector&gt;
   #include &lt;algorithm&gt;
   #include &lt;ctime&gt;
   #include &lt;cmath&gt;
   #include &lt;unistd.h&gt;
  
   //All functions declaration
  
  
   int main(){
  //function which read all the sample to analyse
  
  for (int sample=0;sample&lt;numOfSamples;sample++){
  
   srand(time(NULL));
  
  float tMax = tMax();//A function which calculates the maxium time for that sample
  
  clock_t t;
  t=clock();
  
  //Some more functions which are not important
  
  time= (clock()-t)/CLOCKS_PER_SEC;
  
     while(time&lt;tMax){
  
     //Do different functions
  
      time=(clock()-t)/CLOCKS_PER_SEC;
     cout&lt;&lt;"Timer: "&lt;&lt;time&lt;&lt;endl;
  
     }//End of while
  }//End of For Loop (Samples)
  }//ENd of main
  </code></pre>
  
  <p>That's my code, as you see there is no reset on my timer yet because I have no idea how to use it. But the main problem it's the timer time, it's always 0. So it's always lower than tMax.</p>
  
  <p>How can I reset the timer and get a value greater than 0?</p>