Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Scripting Languages (http://www.programmingforums.org/forum39.html)
-   -   Pascal Question (http://www.programmingforums.org/showthread.php?t=4326)

Lightninghawk Jun 6th, 2005 8:23 AM

Pascal Question
 
:

  1. <LI class="code-row code-row-first">Program FormulaResolvente; <LI class=code-row>uses <LI class=code-row>crt; <LI class=code-row>var <LI class=code-row>A : real; <LI class=code-row>B : real; <LI class=code-row>C : real; <LI class=code-row>D : real; {o k ta dentro da raiz kuadrada da formula resolvente} <LI class=code-row>X : real; {coordenada X do vertice} <LI class=code-row>raiz1 : real; <LI class=code-row>raiz2 : real; <LI class=code-row>Begin <LI class=code-row>clrscr; <LI class=code-row>writeln( 'Introduz o valor de A:' ); <LI class=code-row>readln( A ); <LI class=code-row>writeln( 'Introduz o valor de B:' ); <LI class=code-row>readln( B ); <LI class=code-row>writeln( 'Introduz o valor de C:' ); <LI class=code-row>readln( C ); <LI class=code-row>d:= (b*b)-(4*a*c); <LI class=code-row>if d < 0 then <LI class=code-row>writeln('Raizes de nºs negativos nao existem Razz') <LI class=code-row>else <LI class=code-row>raiz1:= (-b+sqrt(d))/(2*a); <LI class=code-row>raiz2:= (-b-sqrt(d))/(2*a); <LI class=code-row>BEGIN <LI class=code-row>writeln('1ª Raiz = ',raiz1); <LI class=code-row>writeln('2ª Raiz = ',raiz2); <LI class=code-row>END; <LI class=code-row>X:= (raiz1+raiz2)/2; <LI class=code-row>Begin <LI class=code-row>writeln('Coordenada X do vertice : ',X); <LI class=code-row>writeln('Coordenada Y do vertice : ',(A*sqr(x))+(B*X)+C); <LI class=code-row>while not keypressed do; <LI class=code-row>end;

  2. end.



Ok, I´ll say what the problem is: the command "while not keypressed do" just function when D<0..well that's a real big problem because D can also be >0 and then the window closes before showing the coordinate of the vertex of the parable...

NOTE: some of this program is in Portuguese, but it should not matter.

Lightninghawk Jun 6th, 2005 8:24 AM

Ok.... umm... Why did it post all short and scrawny like that?

Would someone please tell me how to fix that?

Ooble Jun 6th, 2005 5:14 PM

Sure. Press enter once in a while.

deathseeker25 Jun 6th, 2005 5:36 PM

Hi....LOL...that's my program.... :D :D

Scorpions4ever Jun 7th, 2005 8:17 PM

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.


Ooble Jun 7th, 2005 8:49 PM

Hold on just one second...

http://www.programmingforums.org/for...ead.php?t=4182


All times are GMT -5. The time now is 4:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC