Error lvalue required as left operand of assignment

Asked

Viewed 697 times

0

Someone help me, how can I resolve this error:[Error] lvalue required as left operand of assignment

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

main ()
{
    setlocale(LC_ALL, "Portuguese");
    /* Descubra seu os numeros formam um triangulo
       Programado por Wesley*/

    int a, b, c;

    printf("Descubra se seus numeros formam um triangulo\n");

    printf("Informe o valor do primeiro lado: ");
    scanf("%d", &a);

    printf("Informe o valor do segundo lado: ");
    scanf("%d", &b);

    printf("Informe o valor do terceiro lado: ");
    scanf("%d", &b);

    if (a < b + c && b < a + c && c < a + b) 
    {
      if (a = b && b = c)
      {
        printf("Estes valores formam um triangulo equilátero\n");
      }
      else if (a = b && b = c && a = c) 
        printf("Estes valores formam um triangulo isóceles\n");
      else
        pritnf("Estes valores formam um triangulo escaleno\n");
    }
    else
   {
     printf("Estes valores não formam um triangulo!\n");
   }         

}

2 answers

3

This problem is happening because you put = in their condition, rather than ==. The = is for assignment, when we want to compare two values we use ==. It’s not always a mistake to use = within a condition, see more here.

Your code has other problems:

  • Wrote pritnf in place of printf within the else more internal;
  • The third scanf is reading again the variable b, instead of c;
  • When checking whether the triangle is isosceles is using && instead of ||. Note that to be isosceles it is enough that one of the equalities is satisfied;
  • Also missing type of function main, as well as remembered @zentrunix.

Here’s a demo of the modified code: https://ideone.com/tybZDc

  • 1

    actually the main function type is always "int"...gcc always complained, and still complains, of "void main", Microsoft always accepted (I used so)...from C99 it is mandatory to put the return type of a function in its statement...the "Return 0" is optional, even when using "int main"...and the correct type of main in C is "int main(void)"...in C when declaring a function with parameters "()" instead of "(void)" the meaning is slightly different from C++ ... this OS question has more details

0

There are several errors in the program, noted below

#include <stdio.h>      // <============== FALTANDo
#include <locale.h>

// main ()  // <========  ERRO

int main(void)
{
  setlocale(LC_ALL, "Portuguese");

  /* Descubra seu os numeros formam um triangulo
     Programado por Wesley*/

  int a, b, c;

  printf("Descubra se seus numeros formam um triangulo\n");

  printf("Informe o valor do primeiro lado: ");
  scanf("%d", &a);

  printf("Informe o valor do segundo lado: ");
  scanf("%d", &b);

  printf("Informe o valor do terceiro lado: ");
  // scanf("%d", &b); // <===================== ERRO (@Mauro Roberto)
  scanf("%d", &c);

  if (a < b + c && b < a + c && c < a + b) 
  {
    // if (a = b && b = c) // <============== ERRO
    if (a == b && b == c)
    {
      printf("Estes valores formam um triangulo equilátero\n");
    }
    // else if (a = b && b = c && a = c)  // <=============== ERRO
    else if (a == b || b == c || a == c)  // && --> || (@Mauro Roberto)
      printf("Estes valores formam um triangulo isóceles\n");
    else
      // pritnf("Estes valores formam um triangulo escaleno\n"); // <=========== ERRO
      printf("Estes valores formam um triangulo escaleno\n");
  }
  else
  {
    printf("Estes valores não formam um triangulo!\n");
  }         

}

Browser other questions tagged

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