Autor Beitrag
chriss1988
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 13.12.05 09:33 
hi

wir sollen für die schule :puke:
ein programm schreiben das bei betätigen auf einen radiobutton
die kleinste zahl aus edit1,edit2,edit3 rausliest und in edit 4 dann die kleinste zahl reinschreibt.

und genau an dem punkt hängst bei mir. ich gebe 3 zahlen ein

z.B. edit1=3; edit2=345 edit3=23

normaler weise sollte er mir als kleinste zahle die 3 reinschreiben doch was macht er er schreibt die 23 rein.woran kann das liegen

hier ma mein code

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
  procedure TForm1.RadioButton1Click(Sender: TObject);
  begin
   Zahl1:=strtofloat(edit1.text);
   Zahl2:=strtofloat(edit2.text);
   Zahl3:=strtofloat(edit3.text);

  if zahl1>zahl2 then
   kleinstezahl:=zahl2;
  if zahl1<zahl2 then
   kleinstezahl:=zahl1;
  if zahl1>zahl3 then
   kleinstezahl:=zahl3;
  if zahl1<zahl3 then
   kleinstezahl:=zahl1;
  if zahl2>zahl3 then
   kleinstezahl:=zahl3;
  if zahl2<zahl3 then
   kleinstezahl:=zahl2;

   edit4.text:=floattostrf(kleinstezahl,fffixed,7,2);
  end;
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 13.12.05 09:37 
Es wird am ende überprüft ob zahl 2 größer als zahl 3 ist ! Dies trifft zu, also wird zahl3 die kleinstezahl !

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 13.12.05 09:41 
aha ok
und wie umgehe ich das problem

mit einer else der wie
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 13.12.05 09:52 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure _Swap (var Z1,Z2: real);
var
 H: Real;
begin
  H := Z1;
  Z1 := Z2;
  Z2 := H;
end;


if Zahl3<Zahl2 then Swap (Zahl2,Zahl3);
if Zahl2<Zahl1 then Swap (Zahl1,Zahl2);

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 13.12.05 09:53 
Vergleiche 1. und 2. Zahl, wenn 1 kleiner dann tausche die Zahlen.
Vergleiche 2. und 3. Zahl, wenn 2 kleiner dann tausche die Zahlen.
die 3. Zahl ist nun die Kleinste !

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 13.12.05 10:02 
user profile iconKroko hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure _Swap (var Z1,Z2: real);
var
 H: Real;
begin
  H := Z1;
  Z1 := Z2;
  Z2 := H;
end;


if Zahl3<Zahl2 then Swap (Zahl2,Zahl3);
if Zahl2<Zahl1 then Swap (Zahl1,Zahl2);


geht das net leichter aber trotzdem danke
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 13.12.05 10:03 
user profile iconchriss1988 hat folgendes geschrieben:
user profile iconKroko hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
...					


geht das net leichter aber trotzdem danke

ja, gib in Edit4 die kleinste Zahl ein! :wink:

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 13.12.05 10:06 
;-)

haha das wär zu einfach
stifflersmom
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 194

XP /XP PRO/ SuSE div.
D1 - D7, BDS 2006
BeitragVerfasst: Di 13.12.05 16:48 
Definier doch am Anfang einfach die erste "kleinsteZahl", dann ist der rest kein Problem mehr.
Also so,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
KleinsteZahl := StrToInt(Edit1.Text);

TZahl := StrToInt(edit2.Text);
If Tzahl < KleinsteZahl Then KleinsteZahl := Tzahl;

TZahl := StrToInt(Edit3.text);
If TZahl < KleinsteZahl Then KleinsteZahl := TZahl;


Uns so weiter und so fort...
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 13.12.05 17:05 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  a, b, c, z: integer;
begin
  a := StrToInt(edit1.Text);
  b := StrToInt(edit2.Text);
  c := StrToInt(Edit3.text);

  z := a;
  if b < z then
    z := b;
  if c < z then
    z := c;

  edit4.text := IntToStr(z);
end;

so, ich denke das sollte leicht verständlich sein ;)