Home > front end >  Identifier is undefined (in C)
Identifier is undefined (in C)

Time:11-01

This is the code I am trying to write:

#include <stdio.h>
#include <math.h>

int main() {
    int x1, y1, x2, y2, x3, y3;
    printf("Type coordinates of the first point: ");
    scanf_s("%i%i", &x1, &y1);
    printf("Type coordinates of the second point: ");
    scanf_s("%i%i", &x2, &y2);
    printf("Type coordinates of the third point: ");
    scanf_s("%i%i", &x3, &y3);
    printf("This is the area: %i",
        0.5 * ((x1 * (y2−y3) x2 * (y3−y1) x3 * (y1−y2))); //here i get the error
    return 0;
}

and I get the error at (y2-y3) and (y1-y2) for Identifier is undefined. Why and how can I fix it?

CodePudding user response:

You have a problem with the last printf. it seems you are using an incorrect decrement operator -.

fix it like that:

    printf("This is the area: %lf",
            0.5 * ((x1 * (y2-y3) x2 * (y3-y1) x3 * (y1-y2)))); 

CodePudding user response:

You need to use - instead of

CodePudding user response:

#include <stdio.h>
#include <math.h>

int main() {
    int x1, y1, x2, y2, x3, y3;
    printf("Type coordinates of the first point: ");
    scanf("%i%i", &x1, &y1);
    printf("Type coordinates of the second point: ");
    scanf("%i%i", &x2, &y2);
    printf("Type coordinates of the third point: ");
    scanf("%i%i", &x3, &y3);
    printf("This is the area: %lf",
        0.5 * (x1 * (y2-y3) x2 * (y3-y1) x3 * (y1-y2)));
         //here i get the error
   
      return 0;
}
  1. Your scanf_s doesn't provide the length argument, so some other number is used. It isn't determinate what value it finds, so you get eccentric behaviour from the code. so use scanf() instead of scanf_s()

  2. you used an extra ( on your last printf statement.

  3. you used the wrong type of decrement operator between (y2-y3),(y3-y1) and (y1-y2)

  4. and use %lf instead of %i because your last printf takes the argument of type double

  •  Tags:  
  • c
  • Related