Autor Beitrag
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Fr 28.10.05 16:23 
Hallo,
der Titel ist nicht ganz treffend, aber mir fiel beim besten Willen kein besserer ein. :oops:

:arrow: Zur Frage:
Ich bräuchte zwei Funktionen die mir 2 Zahlen addieren so, dass, falls die addierte Zahl größer ist als der Wert x, bei der addierten Zahl wieder von vorn beginnt zu zählen:
ausblenden Quelltext
1:
2:
3:
4:
x = 20
  zahl := 5 + 5  (=10)
  ABER
  zahl := 10 + 12  (=2)

Sie zweite Funktion soll das gleiche, nur mit Subtraktion und bei "0", machen:
ausblenden Quelltext
1:
2:
3:
  zahl := 10 - 5  (=5)
  ABER
  zahl := 5 - 8  (=3)


Das zweite wäre dann wohl "Betrag von"?!
Wie bekomm' ich das jetzt mit Delphi hin? Gibt's da schon irgendwelche schlauen Funktionen?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 28.10.05 16:31 
Wenn ich dich richtig verstehe, suchst du die Funktion MOD
Es gilt: (5 + 7MOD 10 = 2

_________________
We are, we were and will not be.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 28.10.05 16:31 
Für den ersten Fall könnte das 'modulo' (also der Rest, der bei einer ganzzahligen Division übrigbleibt) verwendet werden.
Für den zweiten Fall willst Du eigentlich den Wert der Substraktion, nur ohne Vorzeichen, also den absoluten Wert.

_________________
Na denn, dann. Bis dann, denn.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Fr 28.10.05 16:32 
wo is da dein problem du hast doch schon alles da stehn ;D
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
begin
  x:= 20;
  zahl:= 10 + 12;

  Repeat 
    If Zahl >= 20 Then zahl:= Zahl - x; //wenn die zahl gleich 20 is kommt null, wenn da ne 20 kommen soll das  "=" weglassen
  Until Zahl < 20;
end;

//und das zweite:
begin
  zahl:= 5 - 8;
  If zahl < 0 Then Abs(zahl);
end;

das wars schon...
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Fr 28.10.05 16:33 
Die erste Funktion läßt sich mit mod realisieren:

ausblenden Quelltext
1:
(10 + 12) mod 20 (= 2)					


Das zweite ist die Betragsfunktion, die heisst in Delphi Abs().

Stefan
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Fr 28.10.05 17:02 
Perfekt, danke!
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 28.10.05 17:15 
Seit Ihr Alle farbenblind?
user profile iconalzaimar hat folgendes geschrieben:
Für den ersten Fall könnte das 'modulo' (also der Rest, der bei einer ganzzahligen Division übrigbleibt) verwendet werden.
Für den zweiten Fall willst Du eigentlich den Wert der Substraktion, nur ohne Vorzeichen, also den absoluten Wert.
.

Da will man mal dezent (Farbe braun) draufhinweisen, und dann wird man einfach ingnoriert :bawling: Pah!

Aber, mir ist das doch gleich :schmoll:

Schönes WE :party:

_________________
Na denn, dann. Bis dann, denn.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Fr 28.10.05 17:35 
mmh ich würd sagen das hier alle ziemlich zur selben zeit angefang haben mit schreiben...
und damit is das hier halt alles 3 mal da :D
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Fr 28.10.05 19:01 
user profile iconIronwulf hat folgendes geschrieben:
mmh ich würd sagen das hier alle ziemlich zur selben zeit angefang haben mit schreiben...
und damit is das hier halt alles 3 mal da :D
:mrgreen: Das kann mir nur recht sein :D

Die Funktionen würden dann (auf meine Bedürfnisse abgestimmt) so aussehen: (falls sich noch andere dafür interessieren ;-))
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function TForm1.TrimToMax(Zahl: real; Max: real): real;
begin
  Repeat
  If Zahl > Max Then
    zahl:= Zahl - Max;
  Until Zahl <= Max;
end;

function TForm1.TrimToMinZeroWithMax(Zahl: real; Max: real): real;
begin
If Zahl < 0 Then
  Zahl := Abs(Zahl);
TrimToMax(Zahl, Max);
end;


mfg