lvalue required as left operand of assignment - rest of division

Asked

Viewed 511 times

2

I’m having a problem making rest of the division. Gave that mistake:

value required as left operand of assignment

How do I fix it?

#include <stdio.h>
#include <stdlib.h>

int main()
{
int x;
printf("informe o numero inteiro: \n");
scanf("%d",&x);
if (x>0)
    {
    printf("numero positivo ");
    }
    else {
        printf("numero negativo ");
    }
if (x % 2 = 0)
{
    printf("e par");
}
    else {
        printf("e impar");
    }

return 0;
}
  • The error is that you used the assignment operator = instead of the comparison ==.

  • Do not forget to check if the program provides the result you expect for x = 0.

1 answer

4


The comparison signal that will work, = is attribution, == is comparison. In an assignment can not have an expression on the left side, only a variable, it was lucky this time, the compiler caught the error, if it had only one variable would work, but it would be wrong.

if (x % 2 == 0)

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.