0
votes

First off, I'm new to programming and I've just started learning pascal. I've encountered an error 85: ";" expected. I searched through the whole thing multiple times but I haven't been able to find the problem. Any suggestions?

Here's the code:

program test;
var
  a,b,c:real;
begin
  D:=sqr(b)-4*a*c;
  writeln('Enter a value for a');
  readln(a);
  writeln('Enter a value for b');
  readln(b);
  writeln('Enter a value for c');
  readln(c);
  if ( D<0 ) then
  begin
    writeln('There is no solution.');
  else
  if ( D>0 ) then
  begin
    x1:=(-b+sqrt(D))/2*a;
    x2:=(-b-sqrt(D))/2*a;
    writeln('x1 is:');
    writeln('x1:=',x1);
    writeln(x2 is:);
    writeln('x2:=',x2);
  end;
end.
2
Didn't you get a line number for where the error occurred? Also, indent your code. - Michael
Nope. It only displayed an error 85. Nonetheless, thanks for your comment and suggestion for indenting my code. I'll try to do it more often in the future. - user3385057

2 Answers

3
votes

You have three begin and only two end statements. Indent your code and you would notice your mistake. Variable D, X1, and X2 are also undefined. There are other syntax errors in your output, ie, missing tic marks 'in one of your writeln statements near the end.

0
votes

And you need a end before the else ..

program test;
var
  a,b,c:real;
begin
  D:=sqr(b)-4*a*c;
  writeln('Enter a value for a');
  readln(a);
  writeln('Enter a value for b');
  readln(b);
  writeln('Enter a value for c');
  readln(c);
  if ( D<0 ) then
  begin
    writeln('There is no solution.');
  end 
  else
  if ( D>0 ) then
  begin
    x1:=(-b+sqrt(D))/2*a;
    x2:=(-b-sqrt(D))/2*a;
    writeln('x1 is:');
    writeln('x1:=',x1);
    writeln(x2 is:);
    writeln('x2:=',x2);
  end;
end.