Thread: Pascal Question
View Single Post
Old Jun 7th, 2005, 8:17 PM   #5
Scorpions4ever
Programmer
 
Join Date: Jun 2005
Posts: 86
Rep Power: 4 Scorpions4ever is on a distinguished road
You've got a couple of missing begin...end blocks here. Because of that, you're evaluating:
raiz2 := (-b - sqrt(d))/(2*a);
even when d is negative, which would cause your program to abort (because of the part in bold text). You also have some unnecessary begin..end blocks.

Restructuring your code around a bit, I ended up with:
program FormulaResolvente;
uses
crt;
var
   A     : real;
   B     : real;
   C     : real;
   D     : real; {o k ta dentro da raiz kuadrada da formula resolvente}
   X     : real; {coordenada X do vertice}
   raiz1 : real;
   raiz2 : real;
Begin
   clrscr;
   writeln( 'Introduz o valor de A:' );
   readln( A );
   writeln( 'Introduz o valor de B:' );
   readln( B );
   writeln( 'Introduz o valor de C:' );
   readln( C );
   d:= (b*b)-(4*a*c);
   if d < 0 then
      writeln('Raizes de nºs negativos nao existem Razz')
   else
   begin
      raiz1:= (-b+sqrt(d))/(2*a);
      raiz2:= (-b-sqrt(d))/(2*a);

      writeln('1ª Raiz = ',raiz1);
      writeln('2ª R    aiz = ',raiz2);
      X:= (raiz1+raiz2)/2;

      writeln('Coordenada X do vertice : ',X);
      writeln('Coord    enada Y do vertice : ',(A*sqr(x))+(B*X)+C);
   end;

   while not keypressed do;
end.
Scorpions4ever is offline   Reply With Quote