Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 6th, 2005, 8:23 AM   #1
Lightninghawk
Programmer
 
Join Date: Jun 2005
Location: Douglas, Ga - USA
Posts: 32
Rep Power: 0 Lightninghawk is on a distinguished road
Send a message via MSN to Lightninghawk Send a message via Yahoo to Lightninghawk
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.
__________________

+_-¤ ŦĦễ £ﺄĢĦŧňĨňĢĦǻщk ¤-_+
- PC Apps Specialist, Networking n00b, programmer in training -

Information Technology Support


Last edited by big_k105; Jun 6th, 2005 at 9:32 AM.
Lightninghawk is offline   Reply With Quote
Old Jun 6th, 2005, 8:24 AM   #2
Lightninghawk
Programmer
 
Join Date: Jun 2005
Location: Douglas, Ga - USA
Posts: 32
Rep Power: 0 Lightninghawk is on a distinguished road
Send a message via MSN to Lightninghawk Send a message via Yahoo to Lightninghawk
Ok.... umm... Why did it post all short and scrawny like that?

Would someone please tell me how to fix that?
__________________

+_-¤ ŦĦễ £ﺄĢĦŧňĨňĢĦǻщk ¤-_+
- PC Apps Specialist, Networking n00b, programmer in training -

Information Technology Support

Lightninghawk is offline   Reply With Quote
Old Jun 6th, 2005, 5:14 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Sure. Press enter once in a while.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 6th, 2005, 5:36 PM   #4
deathseeker25
Programmer
 
Join Date: May 2005
Posts: 48
Rep Power: 0 deathseeker25 is on a distinguished road
Hi....LOL...that's my program....
deathseeker25 is offline   Reply With Quote
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
Old Jun 7th, 2005, 8:49 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Hold on just one second...

http://www.programmingforums.org/for...ead.php?t=4182
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:54 PM.

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