How to avoid this error message? "Main.cpp: 8: 16: error: lvalue required as left operand of assignment" [closed]

-2

I'm getting the error message: "main.cpp: In function 'int main ()': main.cpp: 8: 16: error: lvalue required as left operand of assignment    (-10)) / 76 = n-1; "

In the code snippet below, does anyone know why?

#include 
using namespace std;
int main(){
  int ano;
  cin>>ano;
  int passagem;
  int n;
  (ano-10)/76=n-1;
  passagem=(10+76)*(n-1);

  }'

    
asked by anonymous 23.05.2017 / 17:39

1 answer

1

The equal sign = is used to set values in variables, when you do:

(ano-10)/76=n-1;

You try to set the value of n-1 to the value of (ano-10)/76 , but this does not make sense and causes the fault, the equal sign must be used with variables, such as:

int foo = n-1;
int bar = (ano-10)/76;

But it depends a lot on what you want to do, there is also == which is the comparison sign, for example:

if (foo == bar) {
     //Acontece algo
}
    
23.05.2017 / 17:55