Consider the following code:
int s= int(sr/nt);
int temp1 = 0; //initialization for the first time case
// the following is the logic for the subsequent cases
int temp2= temp1; // a non-zero value of 's', calculated previously and stored in temp1 is now transferred to temp2
temp1 = s; // currently calculated value of 's' stored in temp1
double moving_average = (temp1+temp2)/2; // not relevant to the problem
My problem is that I require the above code to run a number of times when it is called; and need the previous values of 's' stored in temp1 to transfer it to temp2 in order to calculate moving average.
As I initialize temp1 to zero in the code, it will be executed for the subsequent iterations and I won't get what I need.
Any ideas? Thanks in advance