Domanda

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.
È stato utile?

Soluzione

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.

Altri suggerimenti

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top