driger1592
2006-04-30 01:52:13
Whiteshadow wanted help for his homework, this is the result I'm giving him ;) It shows most of the work that goes into it, so it's nice and easy. It has two variables you can get answers from (since two answers usually come out of this). It also shows if there are no solutions. It returns true if there is a solution, and false if there is not. I enjoyed making this one :D
function QuadraticFormula(a,b,c: extended; var answer1,answer2: extended): boolean;
var i: extended;
begin
Writeln('('+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(Sqr(b))+' - 4('+FloatToStr(a)+')('+FloatToStr(c)+'))) / '+FloatToStr(a*2));
i := Sqr(b)-(4*a*c);
If(i<0)Then
begin
Result := false;
answer1 := 0;
answer2 := 0;
Writeln('('+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(i)+')) / '+FloatToStr(a*2)+' - No solutions');
Exit;
end;
i := Sqrt(i);
Writeln('('+FloatToStr(b*-1)+' ± '+FloatToStr(i)+') / '+FloatToStr(a*2));
answer1 := ((b*-1) + i)/(a*2);
answer2 := ((b*-1) - i)/(a*2);
Result := true;
end;Maybe someone else will like this or thank me for it ;)