# too many variables defined

• 06-26-2004
campermama
too many variables defined
This is what I have:
Code:

``` #include <iostream.h> //f(1)=2, f(2)=2, f(n)=2*f(n-1) + f(n-2)  int f(int n)  {         if (n <= 2)         {                 return 2;         }         return (2 * f(n - 1) + f(n - 2));  }      // This part was to test my code.  int main() {   for ( int i = 0; i < 4; ++i )   {       std::cout << "f(" << i << ") = " << f(i) << std::endl;   }   return 0; }```
I am supposed to just compute for f. This defines too many values, it should just define for n >=1, so do I change my 2 to a 1? Not sure here. Thanks!!
• 06-26-2004
Salem
I don't see a problem

Compiles OK and produces
f(0) = 2
f(1) = 2
f(2) = 2
f(3) = 6
• 06-26-2004
campermama
Yes, I know....but I am not supposed to define that many variables, just n>=1. Any ideas?
• 06-26-2004
quzah
There are no variables "defined" inside the function f. The only variable "defined" is i in your test loop.

Quzah.
• 06-27-2004
Salem
Perhaps campermama, you should describe the problem, rather than try to explain a solution.

I get the feeling that f(x) is supposed to produce a different sequence than 2,2,2,6
• 06-27-2004
campermama
I think the problem was I was showing a result for f(0) and that was not part of this recursive,
Code:

``` f(1)=2, f(2)=2, f(n)=2*f(n-1) + f(n-2)```
So I changed my code to just show f(1), f(2), and f(3).