Autor Beitrag
norbinou
Hält's aus hier
Beiträge: 4

Win 2000
delphi6
BeitragVerfasst: So 04.12.05 13:25 
Hallo Leute,

Ich habe eine kleine Programm geschrieben.
1. Es soll ein Wert eingegeben,
2. kommt die Iteration
3. Ausgabe der Ergebniss

Das klappt nicht mit der Iteration, ich nicht woran das liegt?

Danke
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PbInpUtil, Buttons, PbRun;

type
  TForm1 = class(TForm)
    k: TPbFloatEdit;
    c0: TPbFloatEdit;
    Gleichgewichtskonstante: TLabel;
    Anfangskonzentration: TLabel;
    Konzentration_A1: TLabel;
    Konzentration_A2: TLabel;
    A2: TPbFloatEdit;
    A1: TPbFloatEdit;
    Button1: TButton;
    Label1: TLabel;
    x: TPbFloatEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Iteration: Boolean;
implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
begin
  A2.Text;
  if Iteration = false then
    begin
      A1.Flt := sqrt( k.Flt * A2.Flt ) ;
      x.Flt := A1.Flt + 2 * A2.Flt ;
      if ( abs( c0.Flt / (x.Flt - 1) ) ) < 0.0000001 then
        begin
          A1.Flt := Sqrt( k.Flt * A2.Flt );
          x.Flt := A1.Flt + 2 * A2.Flt ;
          Iteration := false;
        end
      else
        A2.Flt := A2.Flt * ( c0.Flt / x.Flt );
        Iteration := true;
    end
  else
    Iteration := true;
end;



end.


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Waldheini
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 32

Win 98SE, XP
D5 St., K3 Prof
BeitragVerfasst: So 04.12.05 22:16 
Ich denke, der Fehler liegt hier:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.Button1Click(Sender: TObject);  
begin  
  A2.Text;  
  if Iteration = false then  
    begin  
      A1.Flt := sqrt( k.Flt * A2.Flt ) ;  
      x.Flt := A1.Flt + 2 * A2.Flt ;  
      if ( abs( c0.Flt / (x.Flt - 1) ) ) < 0.0000001 then  
        begin  
          A1.Flt := Sqrt( k.Flt * A2.Flt );  
          x.Flt := A1.Flt + 2 * A2.Flt ;  
          Iteration := false;  
        end  
      else  
        begin  // Anfang else
          A2.Flt := A2.Flt * ( c0.Flt / x.Flt );  
          Iteration := true;  
        end;  // Ende else
    end;  
end;


ohne begin/end ist Iteration bei jedem Durchlauf true!

P.S.: das letzte else kannst Du auch weg lassen, da der nachfolgende Befehl nur aufgerufen wird, wenn Iteration bereits true ist.
norbinou Threadstarter
Hält's aus hier
Beiträge: 4

Win 2000
delphi6
BeitragVerfasst: So 04.12.05 22:23 
Danke, jetzt es hat geklappt mit dem Iteration