Elapsedtime variable not resetting
startFlag variable never goes to zero because there is a bug in this part of code:

 if ( ( buttonstate == HIGH ) &amp;&amp; startFlag == 1 ){
          **startFlag = 0;**
          endTime = startTime =0;
          elapsedTime = endTime - startTime;
          countstart = 0;
  }