Autor Beitrag
Zlatan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 18:30 
Ich habe den euklid-Algo..(ggT) programmiert, aber bei klick auf den Rechnen button, geht das programm zu grunde wegen Division by 0.
Ich kann den Fehler nicht finden, ich hoffe ihr könnt es. :lupe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
a:= Strtoint(Edit1.Text);
b:= strtoint(Edit2.Text);
if a < b then a:=b; b:=h; h:=a;
while b > 0 do
a:= b;
h:= a mod b;
b:=h;
Panel2.Caption:= inttostr(a);

end;



Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Di 22.03.2011 um 17:33


Zuletzt bearbeitet von Zlatan am Di 22.03.11 18:58, insgesamt 1-mal bearbeitet
Tankard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Administrator
Beiträge: 217
Erhaltene Danke: 96



BeitragVerfasst: Di 22.03.11 18:32 
da fehlt doch noch ein begin end bei der while schleife oder?
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 18:35 
zumindestens stürzt das programm nicht mehr ab, aber ausrechnen tut der auch nichts mehr :autsch:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
a:= Strtoint(Edit1.Text);
b:= strtoint(Edit2.Text);
if a < b then a:=b; b:=h; h:=a;
while b > 0 do begin
a:= b;
h:= a mod b;
b:=h;
Panel2.Caption:= inttostr(a);
 end
end;
der organist
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: Di 22.03.11 18:37 
und ich vermute mal um den Codeblock nach der Abfrage musst du auch noch ein begin und end machen....

EDIT: Was genau willste damit eingentlich machen?

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Di 22.03.11 18:38 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
   a:= Strtoint(Edit1.Text);
   b:= strtoint(Edit2.Text);
   if a < b then 
      a:=b; 
   b:=h; //ist h = 0???
   h:=a;
   while b > 0 do 
   begin
      a:= b;
      h:= a mod b;
      b := h;
      Panel2.Caption:= inttostr(a);
   end;
end;


Quellcode formatieren hilft! Und was auch helfen würde: Benenne deie Variablen verständlich.

Beste Grüße
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 18:39 
h ist eine hilfsvariable der man keinen wert zuweist.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 22.03.11 18:43 
Ist es eigentlich so schwer, drei Zeilen aus der Wikipedia in der richtigen Reihenfolge abzuschreiben? :gruebel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
EUCLID(a,b)
1  solange b <> 0
2      h = a mod b
3      a = b
4      b = h
5  return a

_________________
We are, we were and will not be.
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 18:45 
ja weil ich noch gar nicht auf wiki war :motz:
Einloggen, um Attachments anzusehen!
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 18:50 
Ich habe das nun getauscht(nach deiner ordnung), aber jetzt gibt der was falsches aus und außerdem noch erst beim 2.klick :gruebel:

Jetzt habe ich es so und er gibt einfach das aus, was ich bei edit1 eingetragen habe.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
a:= Strtoint(Edit1.Text);
b:= strtoint(Edit2.Text);
if a < b then a:=b; b:=h; h:=a;
while b > 0 do begin
h:= a mod b;
a:= b
b:=h;
 end;
Panel2.Caption:= inttostr(a);
end;


Zuletzt bearbeitet von Zlatan am Di 22.03.11 18:56, insgesamt 2-mal bearbeitet
der organist
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: Di 22.03.11 18:55 
neuer Quelltext?

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 22.03.11 18:58 
ausblenden Delphi-Quelltext
1:
if a < b then a:=b; b:=h; h:=a;					


Hat tastaro weiter eben auch schon bemerkt, dass das Murks ist. :roll:

_________________
We are, we were and will not be.
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 19:00 
und wie muss es dann lauten?
(am meisten regt mich auf, dass ich es vor gut 5 stunden fertig hatte in der schule und es jetzt zu hause nicht mehr weiß) :autsch:
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Di 22.03.11 19:13 
hat man dir zwar schon mindestens 5 mal gesagt aber:

ausblenden Delphi-Quelltext
1:
begin [...] end;					


ich denk den link zu den grundlagen tutorials muss ich nicht nochmal posten, du schaust eh nicht drauf...
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 19:17 
So????
er gibt jetzt immer null aus :gruebel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
a:= Strtoint(Edit1.Text);
b:= strtoint(Edit2.Text);
if a < b then a:=b; b:=h; h:=a;
begin//
while b > 0 do
h:= a mod b;
a:= b;
b:=h;
end;//
Panel2.Caption:= inttostr(a);
end;
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Di 22.03.11 19:17 
-.- ich spar mir jedes weitere kommentar.

user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
Ist es eigentlich so schwer, drei Zeilen aus der Wikipedia in der richtigen Reihenfolge abzuschreiben? :gruebel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
EUCLID(a,b)
1  solange b <> 0
2      h = a mod b
3      a = b
4      b = h
5  return a


wo muss begin und end wohl hin?


Zuletzt bearbeitet von glotzer am Di 22.03.11 19:18, insgesamt 1-mal bearbeitet
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 22.03.11 19:18 
warum? helf mir doch bitte, ok?
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 617
Erhaltene Danke: 364

W7
Delphi 6 pro
BeitragVerfasst: Di 22.03.11 19:18 
Moin Zlatan,
beim euklidischen Algorithmus müssen die Variablen nicht getauscht werden.
Falls nämlich a<b ist, wird automatisch getauscht (Zeile 7)!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
 procedure TGgtundKgv.StartClick(Sender: TObject);
  var a,a1,b,b1,rest,ggT,kgV:Longint;
  begin
   a:=StrToInt(Z1.Text);b:=StrToInt(Z2.Text);a1:=a;b1:=b;
   repeat
    rest:=a mod b;
    a:=b;b:=rest
   until rest=0;
   ggT:=a;kgV:=(a1*b1) div ggT;
   ggTAusgabe.Text:=IntToStr(ggT);
   kgVAusgabe.Text:=IntToStr(kgV);
  end;

Gruß
Fiete

_________________
Fietes Gesetz: use your brain (THINK)

Für diesen Beitrag haben gedankt: Zlatan
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 22.03.11 19:20 
Da hier keinerlei Eigeninitiative erkennbar ist, ist dieses Thema jetzt für 24 Stunden geschlossen. So hat Zlatan Zeit zum Nachdenken.

Morgen abend gehts hier weiter.

_________________
We are, we were and will not be.

Für diesen Beitrag haben gedankt: Christian S., der organist, glotzer, jasocul, Marc., Narses, Webo, Zlatan