Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
// Main program for testing the function
|
||||
//
|
||||
do {
|
||||
Get_Input(10, "Enter a roman numeral: ", NOCR+STATLINE)
|
||||
Call("Roman_to_Arabic")
|
||||
Reg_Type(10) Message(" = ") Num_Type(#1)
|
||||
} while(#1)
|
||||
Return
|
||||
|
||||
// Convert Roman numeral into numeric value
|
||||
// in: @10 = Roman numeral
|
||||
// out: #1 = numeric value
|
||||
//
|
||||
:Roman_to_Arabic:
|
||||
Buf_Switch(Buf_Free)
|
||||
Ins_Text("M1000 D500 C100 L50 X10 V5 I1") Ins_Newline
|
||||
Reg_Ins(10) Ins_Char(' ')
|
||||
#1 = #2 = 0
|
||||
|
||||
Repeat(ALL) {
|
||||
#3 = #2 // #3 = previous character
|
||||
Goto_Line(2) // roman numeral to be converted
|
||||
if (At_EOL) {
|
||||
Break // all done
|
||||
}
|
||||
Reg_Copy_Block(11, CP, CP+1, DELETE) // next character in roman numeral
|
||||
if (Search(@11, BEGIN+ADVANCE+NOERR)) { // find character from the table
|
||||
#2 = Num_Eval(SUPPRESS) // corresponding numeric value
|
||||
if (#2 > #3) { // larger than previous digit?
|
||||
#1 -= #3 // substract previous digit
|
||||
} else {
|
||||
#1 += #3 // add previous digit
|
||||
}
|
||||
}
|
||||
}
|
||||
Reg_Empty(11)
|
||||
Buf_Quit(OK)
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue