预期为“ END”,但找到“ IF”。在Turbo Pascal代码中遇到了一些问题

时间:2019-02-25 09:45:03

标签: pascal turbo-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.

2 个答案:

答案 0 :(得分:0)

我认为您想这样做:

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.

答案 1 :(得分:0)

$(function () {
    $(document).on("click", "#modalButton", function () {
         $('#modal').modal('show')
            .find('#modalContent')
            .load($(this).attr('value'));
    });
});

也可能编译为

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

代替使用

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