Autor Beitrag
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 20.01.05 20:14 
Hallo, ich habe ein Problem, ich möchte ? hoch? ausrechnen, doch es gibt immer den Wert 0 zurück.
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:
var
  Form1: TForm1;
  z1,erg:int64;
  i,z2:longint;



function high (erg,z1:int64;z2:longint):int64;
begin
for i  := 1 to z2 do begin
   z1:=z1*z2;

end;
erg:=z1;
end;





procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
z2:=strtoint(zhoch.Text);
z1:=2;
high(z1,z2,erg);
label3.Caption:='='+inttostr(erg);
label3.Visible:=true;
end;


Weiss jemand den Fehler?
Wäre sehr dankbar, denn ohne die function hats geklapt.
Oder gibt es eine elegantere möglichkeit?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 20.01.05 20:23 
Zuerst mal fällt dieser Fehler auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function high (erg,z1:int64;z2:longint):int64;
begin
for i  := 1 to z2 do begin
   z1:=z1*z2;

end;
result :=z1; // <---
end;

Außerdem bieten sich Funktionen wie exp() und power() an.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 20.01.05 20:24 
hast du dir schonmal power angeschaut?
ansonsten enthält dein code soviele Fehler, das man gar nicht weiß, wo man anfangen soll.
Soll high nun eine function oder prozedure sein? Wenn es eine Funktion darstellen soll, warum verwendest du nicht den Rückgabewert? Wenn es eine Prozedure sein soll, muß es
ausblenden Delphi-Quelltext
1:
procedure high (Var erg;z1:int64;z2:longint):int64;					

heißen.
uund dein aufruf: high(z1,z2,erg); hier stimmt die Reihenfolge der paramter nicht.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 20.01.05 20:30 
Wie meinst du warum verwende ich nicht den Rückgabewert, das Problem ist dass ich ein vollkommener Laie bin was Programmieren anbelangt. und Mit der Prozedur geht es nicht. und meine Frage, warum result:=...?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 20.01.05 20:37 
hier, lies dir das erstmal durch: www.dsdt.info/grundl...sprache/prozfunk.php

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 20.01.05 20:40 
Ich habe die Delphi Hilfe zu exp und power angeschaut, doch daraus werde ich auch nicht schlau.
Kann mir jemand das in ei¨nem beispiel verdeutlichen?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 20.01.05 20:43 
Keldorn hat folgendes geschrieben:
Wenn es eine Prozedure sein soll, muß es
ausblenden Delphi-Quelltext
1:
procedure high (Var erg;z1:int64;z2:longint):int64;					

heißen.
Eine Prozedur mit Rückgabewert ist doch mal was ganz Neues. :lol:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 20.01.05 20:48 
Danke, hab alle Probs besetigt:
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:
25:
var
  Form1: TForm1;
  xx,z1,erg:int64;
  i,z2:longint;

function high (Var z1:int64;z2:longint):int64;
begin
xx:=z1;
for i  := 1 to z2-1 do begin
   xx:=xx*z1;

end;
result:=xx;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
z2:=strtoint(zhoch.Text);
z1:=2;
erg:=high(z1,z2);
label3.Caption:='='+inttostr(erg);
label3.Visible:=true;
end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 20.01.05 20:56 
Christian S. hat folgendes geschrieben:
Keldorn hat folgendes geschrieben:
Wenn es eine Prozedure sein soll, muß es
ausblenden Delphi-Quelltext
1:
procedure high (Var erg;z1:int64;z2:longint):int64;					

heißen.
Eine Prozedur mit Rückgabewert ist doch mal was ganz Neues. :lol:

ok, hast mich :wink: . wieder ein Besipiel, warum copy&paste nichts bringts :mrgreen:

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)