unit realroots; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Spin; type Tfactorcalc = class(TForm) a: TSpinEdit; b: TSpinEdit; c: TSpinEdit; root1: TEdit; root2: TEdit; factorize: TButton; done: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; notice: TLabel; procedure doneClick(Sender: TObject); procedure factorizeClick(Sender: TObject); procedure hideme(Sender: TObject); private { Private declarations } public { Public declarations } end; var factorcalc: Tfactorcalc; implementation {$R *.DFM} procedure Tfactorcalc.hideme(Sender:TObject); begin {vanilla code used in the onchange property of each spin edit to tidy up the screen inbetween trials} root1.Visible := false; root2.Visible := false; notice.caption := ''; end; procedure Tfactorcalc.doneClick(Sender: TObject); begin close end; procedure Tfactorcalc.factorizeClick(Sender: TObject); {conditionally executes parts of the quadratic root equation thingy depending on the value of the the thing inside the square root} var determinant : real; {the thing inside the square root} begin determinant := sqr(b.value) - 4*a.value*c.value; if determinant < 0 then notice.caption := 'there are no real roots' {as there is no such thing as the root of a negative} else if determinant = 0 then begin notice.caption := 'there is ONE real root'; root1.text := floattostr(-b.value /(2*a.value)); root1.visible := true end else begin notice.caption := 'there are TWO real roots'; root1.text := floattostr((-b.value+ sqrt(determinant)) /(2*a.value)); root2.text := floattostr((-b.value- sqrt(determinant)) /(2*a.value)); root1.visible := true; root2.visible := true end end; end.