Reputation: 11
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.
Upvotes: 0
Views: 2811
Reputation: 4193
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.
Upvotes: 0
Reputation: 466
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.
Upvotes: 3