Autor Beitrag
julian2304
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 26



BeitragVerfasst: Di 12.06.07 15:49 
Hallo!

Ich habe folgendes Problem. Wenn ich Brüche durch 5 kürze soll der gekürzte Wert nur angezeigt werden,
wenn ein glatter Bruch rauskommt, also ein Bruch ohne "Rest". Bei keinem glatten Bruch soll der Bruch stehen bleiben.
Es sollen 2 procedures verwendet werden.
Bei dem angegebenen Delphi-Code funktioniert es nur manchmal aus irgendwelchen unbekannten Gründen!?!?

Danke für eure Hilfe!!

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:
26:
27:
28:
29:
var
  Form1: TForm1;
  zaehler,nenner:integer;

implementation

{$R *.DFM}

procedure kuerze_mit_5 (Var zaehler,nenner:integer);
begin
if zaehler mod 5 = 0
then
begin
 zaehler:=zaehler div 5;
 nenner :=nenner div 5;
end;
end;

procedure TForm1.button_kuerzeClick(Sender: TObject);

begin
zaehler:=strtoint (edit_zaehler.text);
 nenner:=strtoint  (edit_nenner.text);
  kuerze_mit_5 (zaehler,nenner);
 edit_zaehler2.text:= inttostr (zaehler);
 edit_nenner2.text :=  inttostr  (nenner);
end;

end.


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Di 12.06.07 15:54 
Ich weis irgendwie nicht genau, was ein glatter Bruch ist (mal davon abgesehen, dass mein Bein mal von sowas befallen war :D ) beschreib doch mal genauer, was du damit meinst ;)

gruss, Rob

_________________
erare humanum est
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Di 12.06.07 15:57 
du überprüfst zwar ob der zähler mit 5 teilbar ist aber nicht ob das mit dem Nenner auch klappt
julian2304 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 26



BeitragVerfasst: Di 12.06.07 15:58 
ok

also ein galtter bruch:

15 / 50 = 3 / 10 -> nur wenn zähler und nenner durch 5 teilbar sind, soll geteilt werden ( "mod=0" ; Rest=0)

kein glatter bruch:

16 / 50 = 3 (Rest:1) / 10 -> hierbei soll der bruch stehen bleiben, also 16/50 = 16/50
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Di 12.06.07 15:59 
Dann hat yannik deine Frage soeben beantwortet ;)

ps.: Was soll es überhaupt bringen, den bruch nur und gerade mit 5 zu kürzen?

_________________
erare humanum est
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 12.06.07 16:07 
kürzen am besten mit kgv. dazu brauchst du aber noch den ggt.
julian2304 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 26



BeitragVerfasst: Di 12.06.07 16:08 
@ Jann1k: wie soll das denn dann funktionieren

so geht es nicht

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure kuerze_mit_5 (Var zaehler,nenner:integer);
begin
if zaehler mod 5 = 0
then
begin
 zaehler:=zaehler div 5;
 nenner :=nenner div 5;
end
else
 if
nenner mod 5 = 0
  then
  begin
  zaehler:=zaehler div 5;
 nenner :=nenner div 5;
 end;
end;


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Di 12.06.07 16:12 
ausblenden Delphi-Quelltext
1:
 if (Zaehler mod 5 = 0) and (Nenner mod 5 = 0) then ...					

_________________
erare humanum est
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.06.07 16:30 
Moin!

Warum berechnest du nicht einfach den GGT(Zähler,Nenner), teilst dadurch und hast gleich einen vollständig gekürzten Bruch? :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.