DISCLAIMER!
[+] Running this program will destroy your computer so don't do it!
[+] This program is presented here for educational purposes only.
[+] This program shows a really gay way to do square roots since the function returns a string, not a real.
A better way to do it would be to divide the function into 2 with one returning the positive root
and the other returning the negative. Then do all the formatting shit in the buttonClick procedure.

Quadratic Root Program



function root(a, b, c:real):string;
var top1, top2, toproot, bottom, root1, root2:real;
begin
toproot:=sqr(b)- (4*a*c);
If toproot<0 then //cant have a square root
begin
Showmessage('This isn''t a valid quadratic equation');
end;

If toproot>=0 then
begin
top1:=(-b)+ sqrt(toproot);
top2:=(-b)- sqrt(toproot);
bottom:= 2*a;
root1:=top1/bottom;
root2:=top2/bottom;
root:='{'+floattostr(root1)+ ', ' + floattostr(root2)+'}';
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label7.caption:=edit1.text+'x^2'+ ' + ' + edit2.text+'x + ' + edit3.text;
label6.caption:=root(strtofloat(edit1.Text), strtofloat(edit2.Text), strtofloat(edit3.Text));
end;


Image of Delphi form
Written and edited by BJ; Dedicated to my homie G, Mr.Getto;





Hosted by www.Geocities.ws

1