-2
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.
4

2 回答 2

1

我想你想这样做:

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.
于 2019-02-27T08:45:43.940 回答
0
if ...
then if ...
     then ...
     else ...

也可以编译为

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

改为使用

if ...
then begin
     if ...
     then ...
end
else ...
于 2019-04-11T21:20:32.993 回答