Timur gang
Timur gang

Reputation: 41

Fatal: Syntax error, "." expected but ";" found

program Hello;
var

a,b,c,x,d: integer;
x1,x2: real;

begin

readln(a,b,c);

if a = 0 then
begin
    if b = 0 then
    begin
        if c = 0 then
        begin
            writeln('11');
        end
        else 
            writeln('21');
        end;
    end
    else
        writeln('31');
    end;
end
else
    d := b^2 - 4*a*c;

    if d < 0 then
    begin
        writeln('Нет Вещественных корней!');
    end
    else
        x1 := (-b + sqrt(d))/(2*a);
        x2 := (-b - sqrt(d))/(2*a);
        writeln('Первый Корень:' + x1 + ' ' + 'Второй Корень:' + x2);
    end;
end;
end.

Upvotes: 0

Views: 2906

Answers (1)

MartynA
MartynA

Reputation: 30745

The reason for this is that your begins and ends are not balanced; disregarding the opening begin and closing end. for the program's syntax to be correct, you should have equal numbers of each, but you have 4 begins and 8 ends.

Obviously, your code is to compute the solutions of a quadratic equation. What I think you should do is to adjust the layout of your code so that it reflects that and then correctly the begins and ends. In particular, your program is trying to detect whether any of a, b and d is zero and, if so, write a diagnostic message, otherwise calculate the roots by the usual formula.

Unfortunately, your begins and ends do not reflect that. Either the whole of the block starting d := ... needs to be executed or none of it does, so the else on the line before needs to be followed by a begin, as in

  else begin
    d := b*b - 4*a*c;  //b^2 - 4*a*c;
    if d < 0 then begin
      writeln('Нет Вещественных корней!');
    end
    else begin
      x1 := (-b + sqrt(d))/(2*a);
      x2 := (-b - sqrt(d))/(2*a);
//      writeln('Первый Корень:' + x1 + ' ' + 'Второй Корень:' + x2);
      writeln('Первый Корень:', x1, ' Второй Корень:' , x2);
    end;
  end;

(You don't say which Pascal compiler you are using, but the above fixes two points which are flagged as errors in FreePascal.

If you need more help than that, please ask in a comment.

Btw, there are some grammatical constructs in Pascal implementations where an end can appear without a matching preceding begin such as case ... of ...end.

Upvotes: 2

Related Questions