0

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.
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
user3385057
  • 11
  • 1
  • 2
  • 2
    Didn't you get a line number for where the error occurred? Also, indent your code. – Michael Mar 05 '14 at 19:41
  • 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 Mar 05 '14 at 20:38

2 Answers2

3

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.

Brian English
  • 466
  • 2
  • 8
  • Thank you for correcting me. I will try to indent my code in the future and also check it more carefully for any msitakes. – user3385057 Mar 05 '14 at 20:35
  • Yes, it is misleading. It was caused by the semicolon at the end of the `writeln('There is no solution.');` line of code. It would be better if the compiler would output `"Remove semicolon from statement prior to else clause"`. In Pascal, if there is an `else` then there must never be a semicolon on the previous statement. – Brian English Mar 06 '14 at 21:10
0

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.
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41