Wątek przeniesiony 2018-11-06 20:24 z Delphi i Pascal przez furious programming.

Obliczanie delty – program nie podaje mi wyników

0

Siema, jestem początkującym programistą i potrzebowałbym pomocy. Podczas uruchomienia programu liczącego deltę program nie podaje mi wyników, ktoś mógłby mi powiedzieć co zrobiłem nie tak ?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Math;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    GroupBox2: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Edit4: TEdit;
    Edit5: TEdit;
    GroupBox3: TGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var A,B,C: Extended;
    D,PzD,x1,x2,liczba_x1,liczba_x2: Extended;
begin
if (edit1.text='')or(Edit2.text='')or(edit3.text='')then ShowMessage('Podaj A,B lub C')
  else
    begin
      try
      A:=StrToFloat(edit1.Text);
      B:=StrToFloat(edit2.Text);
      C:=StrToFloat(edit3.Text);
        if(a=0)then ShowMessage('A musi byc rozne od zera.')
          else
            begin
              D:=SQRT(B)-4*A*C;
              if(D>0)then
                begin
                  PzD:=SQRT(D);
                  x1:=(-B-PzD)/(2*A);
                  x2:=(-B+PzD)/(2*A);
                  edit4.visible:=True;
                  edit5.visible:=True;
                  edit6.visible:=True;
                  edit7.visible:=True;
                  liczba_x1:=RoundTo(x1,-2);
                  liczba_x2:=RoundTo(x2,-2);
                  Edit4.Text:=FloatToStr(D);
                  Edit5.Text:=FloatToStr(PzD);
                  Edit6.Text:=FloatToStr(liczba_x1);
                  Edit7.Text:=FloatToStr(liczba_x2);





                end
                else
                  begin
                  if(D=0)then
                  begin
                  x1:=(-B)/(2*A);

                  edit4.visible:=False;
                  edit5.visible:=False;
                  edit6.visible:=False;
                  edit7.visible:=False;
                  liczba_x1:=RoundTo(x1,-2);
                  liczba_x2:=RoundTo(x2,-2);
                  Edit4.Text:=FloatToStr(D);

                  Edit6.Text:=FloatToStr(liczba_x1);
                  


                  
                  end
                  else
                  begin
                  edit4.visible:=True;
                  edit5.visible:=True;
                  edit6.visible:=True;
                  edit7.visible:=True;


                  end;




                  end;




            end;

      except
      ShowMessage('Bledne parametry wejsciowe.');
      end;
      
    end;

end;

end.
1
D:=SQRT(B)-4*A*C;

To nie jest prawidłowy wzór na obliczenie delty – musisz spotęgować B, a nie go pierwiastkować.

0

Wielkie dzięki po zmienieniu na SQR zadziałało jak trzeba :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1