I am trying to collect from a timer that I have set (hh:mm:ss) and average a counted quantity (laps) to come up with a running “laps per hour” output that is accurate as possible (up to the second).

my variables are unsigned long and lapsPh is int.

```
elapsedTime = millis()/1000 - startTime;
elapsedSec = elapsedTime%60;
elapsedMin = (elapsedTime%3600)/60;
elapsedHr = elapsedTime/3600;
```

I tried this-

```
//Laps Per Hour (Average)
if (elapsedSec < 15) //If counter is less than 15sec
{
lapsPh = counter * 240;
}
else if (elapsedSec < 30) //If counter is less than 30sec
{
lapsPh = counter * 120;
}
else if (elapsedSec < 45) //If counter is less than 45sec
{
lapsPh = counter * 80;
}
if (elapsedMin >= 1) //If counter is over 1 minute
{
lapsPh = (counter * 60) / elapsedMin;
}
else if (elapsedHr >= 1) //If countr is over 1 hour, averages minutes as well
{
lapsPh = (counter / (((elapsedHr*60)+elapsedMin) / 60));
}
```

It does work, but on lcd.print(lapsPh); if it gets over 1000 and then drops back down it doesn’t clear all of the printed digits… and I tried if statements to lcd.print(’ ') if a variable is greater than or less than a certain amount but end up with erraneous digits that overflow.

The math is good for each one (verified with fixed numbers in excel), but there should be a more efficient way to do this that also updates better.

Can anyone help steer me in the right direction?

Thanks.

```
Full code removed
```