> Hi!
> I am currently writing a program in Turbo Pascal 7.0 that solves
equations.
> I am having problems with the procedure that calculates the x for f(x)=0.
> I'm using a repeat-loop, that increments the x for each loop and
calculates
> f(x). However, the loop does not stop when f(x) is 0. If anyone could help
> me with this, I would be greatful.
> (Procedure Polydiv(a,b,c,d:Real)
> Thanks
> --PROGRAM--
> Program Equation;
> Uses Crt;
> Const Des=5;
> Var
> inequa:Array[0..4] Of Real;
> ch:Char;
> ok:Boolean;
> Procedure FilledBox(x1,y1,x2,y2,color:Byte);
> Var
> i:Integer;
> x,y:Integer;
> Screen:Array[0..3999] Of Byte Absolute $b800:0000;
> Begin
> TextBackground(color);
> If y1=y2 Then
> Begin
> GotoXY(x1,y1);
> For i:=x1 To x2 Do Write(' ');
> End
> Else
> Begin
> GotoXY(x1,y1);
> For y:=y1 To y2 Do For x:=x1+1 To x2-1 Do
> Begin
> GotoXY(x,y);
> Write(' ');
> End;
> GotoXY(x1,y1);
> Write('');
> For i:=x1 To x2-2 Do Write('?');
> Write('?');
> For i:=y1+1 To y2-1 Do
> Begin
> GotoXY(x1,i);
> Write('3');
> GotoXY(x2,i);
> Write('3');
> End;
> GotoXY(x1,y2);
> Write('');
> For i:=x1 To x2-2 Do Write('?');
> If (x2=80) And (y2=25) Then
> Begin
> Screen[3998]:=Ord('');
> Screen[3999]:=TextAttr;
> End
> Else Write('');
> End;
> End;
> Procedure Seconddegree(a,b,c:Real);
> Var
> Ans:Array[0..2] Of Real;
> Test:Real;
> Begin
> TextBackground(0);
> Test:=(Sqr(b))-(4*a*c);
> If Test<0 Then
> Begin
> GotoXY(3,22);
> Write('Square root of a negative number does not exist - can''t solve
> equation!');
> Exit;
> End;
> If a=0 Then
> Begin
> GotoXY(3,22);
> Write('Can''t divide by zero - impossible to solve equation!');
> Exit;
> End;
> Ans[1]:=(-b+Sqrt((Sqr(b))-(4*a*c)));
> Ans[1]:=Ans[1] / (2*a);
> Ans[2]:=(-b-Sqrt((Sqr(b))-(4*a*c)));
> Ans[2]:=Ans[2] / (2*a);
> If Ans[1]=Ans[2] Then
> Begin
> GotoXY(3,23);
> Writeln('X=',Ans[1]:0:des);
> End
> Else If Frac(Ans[1])=0 Then
> Begin
> GotoXY(3,21);
> Writeln('X=',Ans[1]:0:0);
> GotoXY(3,23);
> If Frac(Ans[2])=0 Then Writeln('X=',Ans[2]:0:0)
> Else Writeln('X=',Ans[2]:0:des);
> End
> Else If Frac(Ans[2])=0 Then
> Begin
> GotoXY(3,21);
> If Frac(Ans[1])=0 Then Writeln('X=',Ans[1]:0:0)
> Else Writeln('X=',Ans[1]:0:des);
> GotoXY(3,23);
> Writeln('X=',Ans[2]:0:0);
> End
> Else
> Begin
> GotoXY(3,21);
> Writeln('X=',Ans[1]:0:des);
> GotoXY(3,23);
> Writeln('X=',Ans[2]:0:des);
> End;
> End;
> Procedure Second_Equa;
> Begin
> Repeat
> FilledBox(1,1,80,8,0);
> FilledBox(1,9,80,18,4);
> FilledBox(1,19,80,25,0);
> GotoXY(3,3);
> Write('SECOND-DEGREE EQUATION');
> GotoXY(3,6);
> Write('axy+bx+c=0');
> TextBackground($4);
> GotoXY(3,11);
> Write('a=');
> Readln(inequa[1]);
> GotoXY(3,13);
> Write('b=');
> Readln(inequa[2]);
> GotoXY(3,15);
> Write('c=');
> Readln(inequa[3]);
> Seconddegree(inequa[1],inequa[2],inequa[3]);
> GotoXY(60,4);
> Write('Again? [Y/N]: ');
> ch:=ReadKey;
> ch:=UpCase(ch);
> ok:=ch In ['N'];
> Until ok;
> End;
> Procedure Polydiv(a,b,c,d:Real);
> Var
> Ans:Array[0..3] Of Real;
> r,t:Real;
> Begin
> TextBackground($0);
> t:=0;
> If ((a*(Sqr(t)*t))+(b*(Sqr(t)))+(c*t)+d)<>0 Then
> Begin
> GotoXY(3,21);
> Write('Calculating...');
> Repeat
> t:=t+0.00000001;
> r:=a*(t*t*t)+b*(t*t)+(c*t)+d;
> GotoXY(3,22);
> Write(r:0:des);
> Until r=0;
> End;
> Ans[1]:=t;
> GotoXY(3,21);
> Write('X=',Ans[1]:0:des,' ');
> GotoXY(2,22);
> Write(' ');
> End;
> Procedure Third_Equa;
> Begin
> Repeat
> TextColor($F);
> FilledBox(1,1,80,8,0);
> FilledBox(1,9,80,17,4);
> FilledBox(1,18,80,25,0);
> GotoXY(3,3);
> Write('THIRD-DEGREE EQUATION');
> GotoXY(3,6);
> Write('ax+bxy+cx+d=0');
> TextBackground($4);
> GotoXY(3,10);
> Write('a=');
> Readln(inequa[1]);
> GotoXY(3,12);
> Write('b=');
> Readln(inequa[2]);
> GotoXY(3,14);
> Write('c=');
> Readln(inequa[3]);
> GotoXY(3,16);
> Write('d=');
> Readln(inequa[4]);
> Polydiv(inequa[1],inequa[2],inequa[3],inequa[4]);
> GotoXY(60,4);
> TextBackground($0);
> Write('Again? [Y/N]: ');
> ch:=ReadKey;
> ch:=UpCase(ch);
> ok:=ch In ['N'];
> Until ok;
> End;
> Begin
> Third_Equa;
> End.