What I am trying to achieve in the following code is to find moving average;
int slots = int ((sr+e)/mst); // finding number of slots
int temp2;
int temp1;
if (temp1 == null)
{
temp2 = 0;
}
temp2=temp1; // previously found number of slots
temp1=slots; // presently found number of slots
double mov_avg = (temp2+temp1)/2; //moving average
The problem is when I compile, I get a warning of temp1 being uninitialised; upon doing a small research, I found that variables do not store null value or zero value on default in C++ when it is uninitialised;
I cannot put a line as temp1 = 0 in the code as its value will be required for the next iteration to be passed on to the temp2 variable; both of which will be required to compute the moving average.
So, basically this a problem for the first time functioning of the above procedure; because if you get past it, the above logic would be sufficient for the moving average calculation. What do you guys think?
Thanks in advance.