Pascal编译错误

Pascal编译错误,pascal,Pascal,代码如下: program pi18; var a,b,c,P:real; begin read(a,b,c); if(a+b<c) or (b+c<a) or (a+c<b) then writeln('Nu exista asa triunghi') else begin P:=a+b+c; if(a=b) and (a=c) then write('Triunghiul este echil') else

代码如下:

program pi18;
var 
  a,b,c,P:real;
begin
  read(a,b,c);
  if(a+b<c) or (b+c<a) or (a+c<b) then
    writeln('Nu exista asa triunghi')
  else
  begin
    P:=a+b+c;
    if(a=b) and (a=c) then 
      write('Triunghiul este echil')
    else
     if(sqr(a) = sqr(b) + sqr(c)) or (sqr(b) = sqr(a) + sqr(c)) or (sqr(c) = sqr(a) + sqr(b)) then
      write('Triunghiul este dreptunghic'); readln();
    else
      write('Triunghiul este arbitrar'); readln();
  end;
  writeln('Perimetrul este: ', P);
end.
程序pi18;
变量
a、 b,c,P:实数;
开始
读(a、b、c);

如果(a+b如果你想在一个条件为真时执行多个语句,你需要用
begin
end
来包装它们。将它们放在同一行不会自动对它们进行分组。因此你需要
begin
end
围绕以下内容:

write('Triunghiul este dreptunghic'); readln();


由于您没有这样做,它只是将第一条语句作为
if
块进行处理。当它看到
else
语句时,它会报告一个错误,因为前面没有与之匹配的
if
语句。

在Pascal中,如果在这两条语句之间有多条语句,则仍然需要设置begin和end他们:

if(sqr(a) = sqr(b) + sqr(c)) or (sqr(b) = sqr(a) + sqr(c)) or (sqr(c) = sqr(a) + sqr(b)) then
begin
  write('Triunghiul este dreptunghic'); 
  readln();
end
else

您的代码缺少
begin
-
end
,在
if
后面的多个语句中:

if(a=b) and (a=c) then 
  write('Triunghiul este echil') // single statement, no begin-end required (but possible)
else if(sqr(a) = sqr(b) + sqr(c)) or (sqr(b) = sqr(a) + sqr(c)) or (sqr(c) = sqr(a) + sqr(b)) then
begin 
  write('Triunghiul este dreptunghic'); 
  readln();
end
else
begin
  write('Triunghiul este arbitrar'); 
  readln();
end;
为了使这一点更加一致,我甚至会:

if(a=b) and (a=c) then 
begin
  write('Triunghiul este echil')
end
else etc...

欢迎使用Stack Overflow。请花点时间阅读并参考“您可以在此处询问什么和如何提问”中的材料。@Mahonri看起来现在需要再编辑一次;-)那么,有人可以帮助我吗?@xQ确定:使用大括号
{}
它是pascal:),不需要{},也不需要一个字符的外观;(或否)在ELSE具有特殊含义之前。他还需要将语句分组在
ELSE
之后。
if(a=b) and (a=c) then 
begin
  write('Triunghiul este echil')
end
else etc...