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;
}
Your
scanf_sdoesn'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 usescanf()instead ofscanf_s()you used an extra
(on your lastprintfstatement.you used the wrong type of decrement operator between
(y2-y3),(y3-y1)and(y1-y2)and use
%lfinstead of%ibecause your last printf takes the argument of typedouble
