Array to store value each time calculated by equation whenever the function is called

Hello everyone! I am new to c++. I have to calculate a value via equation and store that each time whenever the function is called. I have created an array of size 10 and calculated myValue then tried to store that value. Is this program correct?

1
2
3
4
5
6
7
8
9
10
11
static double
CalculatemyValue(Node* ch)
{ 
	float gamma=0.3;
	double myValue = 0.0;
       int n[10];
       int i = 0;
       n[i] = myValue;
       myValue = ((1-gamma)*n[i-1]) //previous value
return myValue;
} 
Nowhere do you ever increase the value of i. Every time you call this function, you change the value of the first entry in the array. Also, when i is 0 (as it always is), then what will the value of i-l be? What will the value of n[i-1] be?
Should I use a loop here? Actually I had a doubt that If I am using a loop here
n[i] = myValue;
for( int i = 1; i < 10; i++ ) {
myValue = ((1-gamma)*n[i-1])
}
then it will calculate 10 values in first call. While my task is to calculate the only 1 value in each call. In next call it should calculate 2nd myValue and store that Value. In 3rd call it should calculate 3rd myValue and so on.
Hi,

You are also assigning a double value to an int array, which won't fly very well :+)
Then how should I implement it?
Topic archived. No new replies allowed.