预期的“结束”但“如果”找到.在涡轮Pascal代码中遇到了一些问题


program calc;
   var a,b,c,d:real; 
Begin
   write('a=');readln(a);
   write('b=');readln(b);
   write('c=');readln(c);
   if a = 0 then
      if b = 0 then
         if c = 0 then
            writeln('equation undetermined,S=R')
         else
            begin
               d := b * b - 4 * a * c; <<<< missed ';'?
               if (d >= 0) then
                  begin
                     writeln('x1=',(-b-sqrt(d))/(2* a):6:2 ); <<< missed ')' ?
                     writeln('x2=',(-b+sqrt(d))/(2* a):6:2 ); <<< missed ')' ?
                  end;
               else 
                  writeln ('Equation has no real solutions');
            end;
            readln;
End.

我想你想这样做:

Program Calc;
   var a,b,c,d: Real; 
Begin
   Write('a='); ReadLn(a);
   Write('b='); ReadLn(b);
   Write('c='); ReadLn(c);
   if (a = 0) or (b = 0) or (c = 0) then
      WriteLn('equation undetermined,S=R')
   else
      Begin
         d := b * b - 4 * a * c;
         if (d >= 0) then
            Begin
               WriteLn('x1=', (-b - sqrt(d)) / (2 * a):6:2 );
               WriteLn('x2=', (-b + sqrt(d)) / (2 * a):6:2 );
            end;
         else 
            WriteLn('Equation has no real solutions');
      end;
   ReadLn;
End.
if ...
then if ...
     then ...
     else ...

也可能编译为

if ...
then if ...
     then ...
else ...

而是使用

if ...
then begin
     if ...
     then ...
end
else ...

相关内容

  • 没有找到相关文章

最新更新