-2
program calc;
   var a,b,c,d:real; 
Begin
   write('a=');readln(a);
   write('b=');readln(b);
   write('c=');readln(c);
   if a = 0 then
      if b = 0 then
         if c = 0 then
            writeln('equation undetermined,S=R')
         else
            begin
               d := b * b - 4 * a * c; <<<< missed ';'?
               if (d >= 0) then
                  begin
                     writeln('x1=',(-b-sqrt(d))/(2* a):6:2 ); <<< missed ')' ?
                     writeln('x2=',(-b+sqrt(d))/(2* a):6:2 ); <<< missed ')' ?
                  end;
               else 
                  writeln ('Equation has no real solutions');
            end;
            readln;
End.
nabuchodonossor
  • 2,095
  • 20
  • 18
  • 4
    Try formatting and indenting the program. – Marco van de Voort Feb 25 '19 at 09:46
  • Apart from anything else you need a semicolon after `d:=b*b-4*a*c` and you should remove the one immediately before `else writeln ...` – MartynA Feb 25 '19 at 10:15
  • The problem no longer appears. I can run the program, but when I’m introducing 3 numbers, like a=2; b=3; c=4, nothing happens – Daniel Lannister Feb 25 '19 at 10:49
  • That can be, because your sequence of if a = 0 then if b = 0 then if c = 0 then. That will result in no processing when you enter a value different of 0 ... – nabuchodonossor Feb 27 '19 at 08:42
  • I assume, you would like to reduce your 3 ifs to: if (a = 0) or (b = 0) or (c=0) then writeln .... else begin .. end..... see my answer below – nabuchodonossor Feb 27 '19 at 08:43
  • Possible duplicate of [Proper structure syntax for Pascal if then begin end and ;](https://stackoverflow.com/questions/28221394/proper-structure-syntax-for-pascal-if-then-begin-end-and) – Ken White Apr 13 '19 at 22:30

2 Answers2

1

I think you want to do this:

Program Calc;
   var a,b,c,d: Real; 

Begin
   Write('a='); ReadLn(a);
   Write('b='); ReadLn(b);
   Write('c='); ReadLn(c);

   if (a = 0) or (b = 0) or (c = 0) then
      WriteLn('equation undetermined,S=R')
   else
      Begin
         d := b * b - 4 * a * c;
         if (d >= 0) then
            Begin
               WriteLn('x1=', (-b - sqrt(d)) / (2 * a):6:2 );
               WriteLn('x2=', (-b + sqrt(d)) / (2 * a):6:2 );
            end;
         else 
            WriteLn('Equation has no real solutions');
      end;

   ReadLn;
End.
lurker
  • 56,987
  • 9
  • 69
  • 103
nabuchodonossor
  • 2,095
  • 20
  • 18
0
if ...
then if ...
     then ...
     else ...

might also compile as

if ...
then if ...
     then ...
else ...

instead use

if ...
then begin
     if ...
     then ...
end
else ...
eenoog
  • 1
  • 1