Skip to content

Commit 446a705

Browse files
committed
Add comments.
1 parent af4de20 commit 446a705

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/movingAvg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ void movingAvg::begin()
1414
// add a new reading and return the new moving average
1515
int movingAvg::reading(int newReading)
1616
{
17+
// add each new data point to the sum until the m_readings array is filled
1718
if (m_nbrReadings < m_interval)
1819
{
1920
++m_nbrReadings;
2021
m_sum = m_sum + newReading;
2122
}
23+
// once the array is filled, subtract the oldest data point and add the new one
2224
else
2325
{
2426
m_sum = m_sum - m_readings[m_next] + newReading;

0 commit comments

Comments
 (0)