# not an lvalue

• 08-06-2004
swampfox
not an lvalue
k obviously i am a noob, but i have observed the basic courtasies for posting. i searched for it in posts and did not find an answer, anyways...

im trying to write a code to output (part of) the fib sequence, but i keep running into the same problem.
Code:

```#include <iostream.h> int fib1[50]; int a=0;  int b=1; int c=2; int main() {  fib1[a]=1; //sets fib1[whatever # a is] to start out at 1  fib1[b]=1;  fib1[c]=2;  for(int x=0;x<50;x++) //set for 50 repetitions  {   fib1[a]+fib1[b]=fib1[c];  //value in fib1[a]+value in fib1[b]=value in fib1[b]. but for somereason my compiler is saying its not an lvalue   a++; //increments a   b++;   c++;   cout<<fib1[a]<<", ";  //outputs #s  } return 0; }```
i have tried putting the values from the array into int variables, but i had the same problem. same thing happended when i used pointers.
• 08-06-2004
DougDbug
l-value means left-value...
The value on the left side of the = sign, is the "unknown".

x = 5; // This is OK
5 = X; // This is NOT OK

fib1[c] = fib1[a] + fib1[b]; // Try This

In C++ (and in programming in general), the equal-sign does not indicate an equation. It is the assignment operator. It assigns the value of the statement on the right to the variable on the left.
• 08-06-2004
Perspective
>> fib1[a]+fib1[b]=fib1[c];

you have to put the thing being assigned on the left (lvalue)

fib1[c] = fib1[a]+fib1[b];

edit: d'oh, beaten by doug :)
• 08-06-2004
swampfox
ahhh, i see, i should have know that. thanks so much for the help