RosettaCodeData/Task/Roman-numerals-Encode/OpenEdge-Progress/roman-numerals-encode.openedge

37 lines
1.0 KiB
Plaintext

FUNCTION encodeRoman RETURNS CHAR (
i_i AS INT
):
DEF VAR cresult AS CHAR.
DEF VAR croman AS CHAR EXTENT 7 INIT [ "M", "D", "C", "L", "X", "V", "I" ].
DEF VAR idecimal AS INT EXTENT 7 INIT [ 1000, 500, 100, 50, 10, 5, 1 ].
DEF VAR ipos AS INT INIT 1.
DO WHILE i_i > 0:
IF i_i - idecimal[ ipos ] >= 0 THEN
ASSIGN
cresult = cresult + croman[ ipos ]
i_i = i_i - idecimal[ ipos ]
.
ELSE IF ipos < EXTENT( croman ) - 1 AND i_i - ( idecimal[ ipos ] - idecimal[ ipos + 2 ] ) >= 0 THEN
ASSIGN
cresult = cresult + croman[ ipos + 2 ] + croman[ ipos ]
i_i = i_i - ( idecimal[ ipos ] - idecimal[ ipos + 2 ] )
ipos = ipos + 1
.
ELSE
ipos = ipos + 1.
END.
RETURN cresult.
END FUNCTION. /* encodeRoman */
MESSAGE
1990 encodeRoman( 1990 ) SKIP
2008 encodeRoman( 2008 ) SKIP
2000 encodeRoman( 2000 ) SKIP
1666 encodeRoman( 1666 ) SKIP
VIEW-AS ALERT-BOX.