4H
X VW>F >~Td VARIABLES AND THEIR USES
n6 Y1(13) AND Z(13) CONVERSION TABLES ARABIC  ROMAN
x$ L1$ INPUT NUMBER IN STRING FORM
) T NUMBER TYPE, 1 = ROMAN, 2 = ARABIC
1 W(20) INDIVIDUAL CHAR VALUES IN ROMAN NUMBER
O = NUMBER IN INTEGER FORM
* "Romans  Friends  Countrymen  ";
\(30);
"Lend me your Ears."
8 \"A program to translate Roman and Arabic numbers."
0 \"Enter a number in either form and I will"
' \"print it in BOTH forms for you."
\" Roman numbers use :"
"1 " 'I' = 1 'V' = 5 'X' = 10 'L' = 50"
,( " 'C' = 100 'D' = 500, 'M' = 1000 "
6) \"Program written by H.S.J.Purvis."\
@+ "Press 'Return' key to continue ";A1$
J
% This is the main program routine
W(20), Y1(13), Z(13)
2 read constants for converting to ROMAN format
$
. A = 1 13
8 Y1$(A),Z(A)
B A
L
V. use of for next to avoid the dreaded GOTO
`
j A = 1 32000
t
~ Fetch a number
2000
Check for 'STOP'
 L1$ = "STOP" L1$ = "stop" *A 1400
determine type
3000
Decode it
T = 1 4000 5000
Check size of Number
(
2 O > 10000 1390
<
F Print the number
P
Z 6000
d
n A
x : Program EXIT point
subroutine to fetch number
= \"Please enter a number in either ROMAN or ARABIC Form."
9 "To stop the program type 'STOP' instead of number."
257,1
"?";L1$
L1$ = "" 2030
*
+ subroutine to determine type of number
) if any of characters 0  9 is found
$ number is assumed to be ARABIC.
T = 1
C = 1 (L1$)
4 L1$(;C,C) >= "0" L1$(;C,C) <= "9" T = 2
C
( Subroutine to decode a ROMAN number
C = 1 (L1$) + 1
W(C) = 0
C
2 Convert each legal ROMAN symbol to it's value
C = 1 (L1$)
C1$ = L1$(;C,C)
C1$ = "I" W(C) = 1
C1$ = "V" W(C) = 5
" C1$ = "X" W(C) = 10
, C1$ = "L" W(C) = 50
6 C1$ = "C" W(C) = 100
@ C1$ = "D" W(C) = 500
J C1$ = "M" W(C) = 1000
T C
^
h0 If current value >= next value add to total
r< If current value < next value then subtract from total

O = 0
C = 1 (L1$)
7 W(C) >= W(C+1) O = O + W(C) O = O  W(C)
C
* subroutine to decode an ARABIC number
O = 0
C = 1 (L1$)
D = (L1$(;C,C))  48
) D >= 0 D <= 9 O = O * 10 + D
C
p
z subroutine to print number
+ \" This is the number in ARABIC form "
7000
+ \\" This is the number in ROMAN form."
8000
5 "Please press the 'RETURN' key to continue.";A1$
X
b/ subroutine to print number in ARABIC form.
l
v \\(20);[I10 O];
@
J subroutine to print number in ROMAN form
T
^. Convert number into string of ROMAN chars
h* by subtracting the value of each char
r that is added to the string

S1$ = ""
C = 1 13
D = 1 32000
O < Z(C) * D 8140
S1$ = S1$ + Y1$(C)
O = O  Z(C)
D
C
\\(34  (S1$));S1$
/ Constants used in generating ROMAN numbers
in string form
/ "M",1000,"CM",900,"D",500,"CD",400,"C",100
/ "XC",90,"L",50,"XL",40,"X",10,"IX",9,"V",5
& "IV",4,"I",1
8