Convert the Roman to an Arabic number in VisualG

The Roman numbering system (or Roman numerals) developed in ancient Rome and was used throughout the empire. In this system, the numbers are written with specific letters representing the numbers. The letters are always written in uppercase because there are no lower case letters in the Roman alphabet. The letters are I, V, X, L, C, D, and M. You need to develop a program that converts Roman numerals into Arabic. The rules for the formation of Roman numerals are given below. Each letter corresponds to a specific value: I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 By grouping the above letters we can represent the numbers according to a set of rules: Except V, L and D, the other digits may not be repeated more than three times:

III = 3

XXX = 30

CCC = 300

MMM = 3000

On the right, written by larger numbers, I, X and C add up to the values ​​of the first:

VIII = 5 + 1 + 1 + 1 = 8

LXII = 50 + 10 + 1 + 1 = 62

CLVIII = 158

MCXX = 1000 + 100 + 10 + 10 = 1120

However, if the numbers I, X and C are to the left of the largest numbers, their values ​​are subtracted, for example, in the following order:

IR = 5-1 = 4

IX = 10-1 = 9

XC = 100-10 = 90

I think I know how to do it first. I would enter the value in Roman, the size of the assigned letter value would be n. The size of this letter would assume n-1. Then try to share the letter. I do not know the command in VisualG If you separate the letters and create a variable to save the separation of those letters, the separator would create another variable in this case. If it were zero, then one would do one where i = 0 and i must be less than the size of the letter, and then add +1 would open to check if the division of the letter delimiters = "M ", then s = s + 1000 and inside another one opens, if and when separators[i-1]= "C", then s = s-200, would end this if it opens another if the delimiter = "D", then s = s + 500, and inside another one opens, if and when delimiters[i-1] = "C" then s = s-200 then that would close and another would be opened if separator = "C", then s = s + 100 and inside another one would be opened if the separator were opened[i-1] = "X" and then s = s-20 then it would end if and if it opened another if separator = "L", then s = s + 50 would open another if separator[i-1] = "X" then

s = s-20 then it would end if and if it would open another if separator = "X", then s = s + 10 would open another if if separator[i-1] = "I" then s = s-2 would close if it would then open another if delimiter = "V" then s = s + 5 and the inside would open another if delimiter[i-1] = "I" then s = s-2 would close this if it then opens another if separator = "I" then s = s + 1

then write)

The problem is it's time to separate the letters that the command in VisualG uses to separate the letter or not?

The Copy command is useful only if it separates letters by letter but fails in time, for example, when copying a Roman number. I have to pass this command already with parameters that exist before this Deficinidos copy of this house up to this house (Roman;), which does not have to enter all the parameters for all numbers from 1 to 3999
At the moment the code is like that
// variable declaration section
Vetromano: vector[1..9] of the character
Roman: characters
i: integer
m, c, d, u: signs
Sum: integer

Home |
// section Commands, Procedures, Functions, Operators, etc.
write ("Enter a Roman number to be converted to Arabic")
write ("less than 4000 and greater than 0")
read (roman)
m <- copy (Roman; 1; 2)
c <- copy (Roman; 3; 2)
d <- copy (Roman; 5; 2)
u <- copy (Roman; 7; 2)
for 1 of 1 to Compr (Roman) Knife
if (m = "M") then
Sum <-soma + 1000
if (m-1) then
Total <-soma-200
The End
The End

        write (sum)

end for