Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - arabisch nach roemisch


R-S-Kelly - Mo 27.10.08 15:12
Titel: arabisch nach roemisch
Hallo ich habe ein Problem. ich programmier grad mit delphi ein umrechner von arabischen zahlen nach römischen.
Ich wollte ma fragen ob hier einer mal rüber gucken kann denn irgendwas muss da noch falsch sein.



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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
       procedure TRom.DezimalToRoemisch;
       var
     lDezimal:Integer;
     lRoemisch: String ;
     lErgebnis: Integer  ;
        begin

     lErgebnis := zDezimal div 1000 ;
     if lErgebnis = 10 then lRoemisch:=lRoemisch +'MMMMMMMMMM';
     if lErgebnis = 9 then lRoemisch:=lRoemisch +'MMMMMMMMM'  ;
     if lErgebnis = 8 then lRoemisch:=lRoemisch +'MMMMMMMM'   ;
     if lErgebnis = 7 then lRoemisch:=lRoemisch +'MMMMMMM'    ;
     if lErgebnis = 6 then lRoemisch:=lRoemisch +'MMMMMM'  ;
     if lErgebnis = 5 then lRoemisch:=lRoemisch +'MMMMM'   ;
     if lErgebnis = 4 then lRoemisch:=lRoemisch +'MMMM'    ;
     if lErgebnis = 3 then lRoemisch:=lRoemisch +'MMM'     ;
     if lErgebnis = 2 then lRoemisch:=lRoemisch +'MM'      ;
     if lErgebnis = 1 then lRoemisch:=lRoemisch +'M'       ;
     lErgebnis := zDezimal mod 1000 ;



     lErgebnis := zDezimal div 100 ;
     if lErgebnis = 10 then lRoemisch:=lRoemisch +'CCCCCCCCCC';
     if lErgebnis = 9 then lRoemisch:=lRoemisch +'CCCCCCCCC'  ;
     if lErgebnis = 8 then lRoemisch:=lRoemisch +'CCCCCCCC'   ;
     if lErgebnis = 7 then lRoemisch:=lRoemisch +'CCCCCCC' ;
     if lErgebnis = 6 then lRoemisch:=lRoemisch +'CCCCCC'  ;
     if lErgebnis = 5 then lRoemisch:=lRoemisch +'CCCCC'   ;
     if lErgebnis = 4 then lRoemisch:=lRoemisch +'CCCC'    ;
     if lErgebnis = 3 then lRoemisch:=lRoemisch +'CCC'     ;
     if lErgebnis = 2 then lRoemisch:=lRoemisch +'CC'      ;
     if lErgebnis = 1 then lRoemisch:=lRoemisch +'C'       ;
     lErgebnis := zDezimal mod 100 ;


     lErgebnis := zDezimal div 10 ;
     if lErgebnis = 10 then lRoemisch:=lRoemisch +'XXXXXXXXXX';
     if lErgebnis = 9 then lRoemisch:=lRoemisch +'XXXXXXXXX';
     if lErgebnis = 8 then lRoemisch:=lRoemisch +'XXXXXXXX';
     if lErgebnis = 7 then lRoemisch:=lRoemisch +'XXXXXXX';
     if lErgebnis = 6 then lRoemisch:=lRoemisch +'XXXXXX' ;
     if lErgebnis = 5 then lRoemisch:=lRoemisch +'XXXXX' ;
     if lErgebnis = 4 then lRoemisch:=lRoemisch +'XXXX' ;
     if lErgebnis = 3 then lRoemisch:=lRoemisch +'XXX';
     if lErgebnis = 2 then lRoemisch:=lRoemisch +'XX' ;
     if lErgebnis = 1 then lRoemisch:=lRoemisch +'X'  ;
     lErgebnis := zDezimal mod 10 ;


     lErgebnis := zDezimal div 1 ;
     if lErgebnis = 10 then lRoemisch:=lRoemisch +'IIIIIIIIII';
     if lErgebnis = 9 then lRoemisch:=lRoemisch +'IIIIIIIII';
     if lErgebnis = 8 then lRoemisch:=lRoemisch +'IIIIIIII' ;
     if lErgebnis = 7 then lRoemisch:=lRoemisch +'IIIIIII' ;
     if lErgebnis = 6 then lRoemisch:=lRoemisch +'IIIIII';
     if lErgebnis = 5 then lRoemisch:=lRoemisch +'IIIII' ;
     if lErgebnis = 4 then lRoemisch:=lRoemisch +'IIII' ;
     if lErgebnis = 3 then lRoemisch:=lRoemisch +'III' ;
     if lErgebnis = 2 then lRoemisch:=lRoemisch +'II'  ;
     if lErgebnis = 1 then lRoemisch:=lRoemisch +'I'   ;
     lErgebnis := zDezimal mod 1 ;

     zRoemisch := lRoemisch;



also das da noch c und so fehlen weiß ich wollte das erstma so hinbekommen, da der mir z.b. bei 1000 MCCCCCCCCCC anzeigt

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt


Jakob_Ullmann - Mo 27.10.08 15:39

lRoemisch hat keinen Startwert. :wink:

EDIT: Benutze bitte die [delphi][/delphi]-Tags.


AXMD - Mo 27.10.08 15:42

Ganz abgesehen davon stimmt das so nicht, was du dir überlegt hast. Du lässt beispielsweise V, L, D unter den Tisch fallen (5, 50 bzw. 500), sowie die Tatsache, dass 4 nicht IIII, sondern IV geschrieben wird, da nicht mehr als 3 gleiche römische Ziffern hintereinander stehen dürfen.

AXMD


Jakob_Ullmann - Mo 27.10.08 15:43

Richtig. Also am Anfang ist es bei der Aufgabe vll besser, erst einmal alle bekannten Regeln aufzuschreiben.

http://de.wikipedia.org/wiki/R%C3%B6mische_Zahl


R-S-Kelly - Mo 27.10.08 15:46

okay..danke


Delete - Di 28.10.08 00:58


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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
function IntToRoman(Value: Longint): string;
Label
  A500, A400, A100, A90, A50, A40, A10, A9, A5, A4, A1;
begin
  Result := '';
{$IFNDEF WIN32}
  if (Value > MaxInt * 2) then Exit;
{$ENDIF}
  while Value >= 1000 do begin
    Dec(Value, 1000); Result := Result + 'M';
  end;
  if Value < 900 then goto A500
  else begin
    Dec(Value, 900); Result := Result + 'CM';
  end;
  goto A90;
A400:
  if Value < 400 then goto A100
  else begin
    Dec(Value, 400); Result := Result + 'CD';
  end;
  goto A90;
A500:
  if Value < 500 then goto A400
  else begin
    Dec(Value, 500); Result := Result + 'D';
  end;
A100:
  while Value >= 100 do begin
    Dec(Value, 100); Result := Result + 'C';
  end;
A90:
  if Value < 90 then goto A50
  else begin
    Dec(Value, 90); Result := Result + 'XC';
  end;
  goto A9;
A40:
  if Value < 40 then goto A10
  else begin
    Dec(Value, 40); Result := Result + 'XL';
  end;
  goto A9;
A50:
  if Value < 50 then goto A40
  else begin
    Dec(Value, 50); Result := Result + 'L';
  end;
A10:
  while Value >= 10 do begin
    Dec(Value, 10); Result := Result + 'X';
  end;
A9:
  if Value < 9 then goto A5
  else begin
    Result := Result + 'IX';
  end;
  Exit;
A4:
  if Value < 4 then goto A1
  else begin
    Result := Result + 'IV';
  end;
  Exit;
A5:
  if Value < 5 then goto A4
  else begin
    Dec(Value, 5); Result := Result + 'V';
  end;
  goto A1;
A1:
  while Value >= 1 do begin
    Dec(Value); Result := Result + 'I';
  end;
end;