Autor Beitrag
Tigu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 17.01.07 18:10 
Hallo!

Ich schreibe gerade an einer Prozedur und bekomme nun eine Fehlermeldung, die ich nicht beseitigen kann. Ist bestimmt ein simpler Fehler, aber mir fällt absolut nichts auf.

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);
var p,q,e,k:integer;
    d:real;

 procedure kfinden(p,q,e,k:integer);
 begin
 if (((1+k*((p-1)*(q-1)))/e) mod k) = 0 then         //Fehler (Operator nicht anwendbar)
  begin
  d:=((1+k*((p-1)*(q-1)))/e);
  end
  else
  kfinden(p,q,e,k+1);
 end;

begin
p:=7;
q:=11;
e:=5;
k:=1;
end;


Bitte helft mir bei der Fehlersuche.
Danke im Vorraus :zustimm:
Tigu

edit: Fehlermeldung hinzugefügt


Zuletzt bearbeitet von Tigu am Mi 17.01.07 20:19, insgesamt 2-mal bearbeitet
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Mi 17.01.07 18:28 
Mod funktioniert nur für ganze zahlen du müsstest also

ausblenden Delphi-Quelltext
1:
(((1+k*((p-1)*(q-1)))/e) mod k)					


durch

ausblenden Delphi-Quelltext
1:
(((1+k*((p-1)*(q-1))) div e) mod k)					


oder

ausblenden Delphi-Quelltext
1:
Round(((1+k*((p-1)*(q-1))) / e) mod k)					


ersetzen.

grüsse
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 17.01.07 18:32 

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

XP
Delphi 7
BeitragVerfasst: Mi 17.01.07 18:32 
Aber wenn ich jetzt runde, kommt ja so oder so eine ganze Zahl raus und ich möchte ja gerade überprüfen, ob die Gleichung mit der Variablen k eine ganzzahlige Lösung hat.(sorry, wenn das vorher nicht so rüber kam)
Habe auch schon
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
a:=(1+k*((p-1)*(q-1)))/e) 
if a mod k = 0 then
...


ausprobiert, bekomme aber den selben Fehler.

Da mein Quelltext ja anscheinent falsch ist, würde ich mich über Vorschläge zur richtigen Programmierung sehr freuen.
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Mi 17.01.07 18:40 
Hi Tigu,

mod ist nur bei Integern anwendbar. Schau mal in die Delphi-Online-Hilfe.

Gruß

Saubäär
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Mi 17.01.07 18:45 
die einfachste lösung wäre es einfach das gerundete mit dem originalen ergebnis zu vergleichen... wenns gleich ist, dann ist es eine ganze zahl.
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 17.01.07 18:59 
So geht es natürlich auch!

Aber warum hat er ein Problem (Stack überlauf), wenn p=13 und q=11 ist? Wie hoch dürfen die Zahlen denn maximal sein, bzw. wie würde man es bei "großeren" Zahlen berechenen?

PS: Bevor es jemand schreibt: ich bin mir bewusst, dass oben noch der Selbstaufruf fehlte.
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Mi 17.01.07 19:30 
Mach das ganze einfach iterativ
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 17.01.07 19:31 
user profile iconRobinator hat folgendes geschrieben:
Mach das ganze einfach iterativ


Was meinst du damit?