我正在用 Pascal 编写程序。并且在条件上有一些麻烦。
例如,如果您输入输入
1 1
1 4
5 1
2 2
tArea1
= 6 和sumAreas
= 6
但在“if”结构中,这不能正常工作。
请帮帮我。肿瘤坏死因子。
var
x1,x2,x3,x4,y1,y2,y3,y4: real;
line1Length, line2Length, line3Length : real; // Length of the triangle area
tArea1, tArea2, tArea3, tArea4, sumAreas : real;
function segmentLength (x,y,x0,y0:real);
begin
segmentLength := sqrt(sqr(x-x0) + sqr(y-y0));
end;
function triangleArea (a,b,c:real);
var
p: real; // Half of the perimetr
begin
p := (a+b+c)/2;
triangleArea := sqrt(p*(p-a)*(p-b)*(p-c));
end;
begin
writeln('write x1,y1');
readln(x1,y1);
writeln('write x2,y2');
readln(x2,y2);
writeln('write x3,y3');
readln(x3,y3);
writeln('write x4,y4');
readln(x4,y4);
// First triangle
line1Length := segmentLength(x1,y1,x2,y2);
line2Length := segmentLength(x2,y2,x3,y3);
line3Length := segmentLength(x3,y3,x1,y1);
tArea1 := triangleArea(line1Length, line2Length, line3Length);
// Second triangle
line1Length := segmentLength(x4,y4,x2,y2);
line2Length := segmentLength(x2,y2,x3,y3);
line3Length := segmentLength(x3,y3,x4,y4);
tArea2 := triangleArea(line1Length, line2Length, line3Length);
// Third triangle
line1Length := segmentLength(x4,y4,x1,y1);
line2Length := segmentLength(x1,y1,x3,y3);
line3Length := segmentLength(x3,y3,x4,y4);
tArea3 := triangleArea(line1Length, line2Length, line3Length);
// Fourth Triangle
line1Length := segmentLength(x4,y4,x1,y1);
line2Length := segmentLength(x1,y1,x2,y2);
line3Length := segmentLength(x2,y2,x4,y4);
tArea4 := triangleArea(line1Length, line2Length, line3Length);
// Check dot situated
sumAreas := tArea4+tArea2+tArea3;
writeln(tArea1, ' // ', sumAreas); //
if (sumAreas = tArea1) then
begin
writeln('In');
end
else
begin
writeln('Out');
end;
end.