Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 14.10.08 15:32 
Hallo,

ich wollte heute mal ein Programm schreiben, das mir die Wurzel aus einer Zahl berechnet und anschließend aus dem Ergebnis wieder die Wurzel usw.

Nun hab ich aber das Problem das es mir immer nur aus der ersten Zahl die Wurzel zieht.

ausblenden 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:
var
  Form1: TForm1;
  zahl : real ;
  i : integer ;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  zahl := StrToFloat(Edit1.Text);
  Timer1.Enabled := true ;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
wurzel : Real ;
begin
  wurzel := sqrt(zahl);
  ListBox1.Items.Add(FloatToStr(wurzel));
end;

end.


Ich weiß ja wo das Problem liegt nämlich das in Wurzel nicht das zuvor errechnete steht und somit folgt das selbe Ergebnis im zweiten wie im ersten Rechenschritt, nur weiß ich leidern nicht ( bzw. komm nicht drauf ) wie ich das umgehen kann !

LG

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 14.10.08 15:38 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Timer1Timer(Sender: TObject);
var
wurzel : Real ;
begin
  wurzel := sqrt(zahl);
  ListBox1.Items.Add(FloatToStr(wurzel));
  zahl := wurzel; //<----
end;
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 14.10.08 15:38 
ausblenden Delphi-Quelltext
1:
zahl := sqrt(zahl);					


Edit: Ok, da wohl nicht ganz deutlich wird, was ich meine:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  zahl := sqrt(zahl);
  ListBox1.Items.Add(FloatToStr(zahl));
end;

_________________
PROGRAMMER: A device for converting coffee into software.


Zuletzt bearbeitet von Xentar am Di 14.10.08 15:39, insgesamt 2-mal bearbeitet
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 14.10.08 15:38 
Merkwürdiges Konstrukt. Wie schauts denn damit aus oder war das zu einfach?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Timer1Timer(Sender: TObject);
 var
   wurzel : Real ;
begin
  wurzel := sqrt(zahl);
  ListBox1.Items.Add(FloatToStr(wurzel));
  zahl := wurzel; 
end;

€: Such Dir eine Lösung aus. :lol:
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 14.10.08 15:40 
user profile iconMarc. hat folgendes geschrieben Zum zitierten Posting springen:
Merkwürdiges Konstrukt. Wie schauts denn damit aus oder war das zu einfach?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Timer1Timer(Sender: TObject);
 var
   wurzel : Real ;
begin
  wurzel := sqrt(zahl);
  ListBox1.Items.Add(FloatToStr(wurzel));
  zahl := wurzel; 
end;

end.


:oops: oha so war das, jetzt fällt es mir auch wieder ein.

Danke @ all funktioniert super :zustimm:

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300