We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent af4de20 commit 446a705Copy full SHA for 446a705
src/movingAvg.cpp
@@ -14,11 +14,13 @@ void movingAvg::begin()
14
// add a new reading and return the new moving average
15
int movingAvg::reading(int newReading)
16
{
17
+ // add each new data point to the sum until the m_readings array is filled
18
if (m_nbrReadings < m_interval)
19
20
++m_nbrReadings;
21
m_sum = m_sum + newReading;
22
}
23
+ // once the array is filled, subtract the oldest data point and add the new one
24
else
25
26
m_sum = m_sum - m_readings[m_next] + newReading;
0 commit comments