Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

easy68k code

Status
Not open for further replies.

TATARA12

New Member
I have my logic down for a program that needs to convert decimal to roman, (maximum number 3999) that needs to return a roman number.

here is my logic in c:

{
if(x>3999)
cout<<"error"<<endl;


while(x>=1000){cout<<"M";x-=1000;}

if(x>=900){cout<<"CM";x-=900;}
else if(x>=500){cout<<"D";x-=500;}
if(x>=400){cout<<"CD";x-=400;}

while(x>=100){cout<<"C";x-=100;}

if(x>=90){cout<<"XC";x-=90;}
else if(x>=50){cout<<"L";x-=50;}
if(x>=40){cout<<"XL";x-=40;}

while(x>=10){cout<<"X";x-=10;}

if(x>=9){cout<<"IX";x-=9;}
else if(x>=5){cout<<"V";x-=5;}
if(x==4){cout<<"IV";x-=4;}

while(x>0){cout<<"I";x-=1;}



return 0;
}

I was going to compare the strings to the values in each register, but I don't think that is the greatest idea.

DECIMAL DC.L '2989'
ENDSTR DC.B 00
ARRAY1 DC.B 3999, $F9F,1000,$4d, 500,$44, 100,$43, 50,$4c, 10,$58, 5,$56, 1,$49, 00,00
;"MMMCMXCIX","M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"

Any suggestions? I do not want the code, I want ideas of how to do this. After I load my register and postincrement it to get to the last value, I compare it to 0 obviously to get to the end. How can I compare it to the roman number, and actually make it return a roman value?
 
While i am a fool in software,
i feel that a look up table defining roman numbers with decimal, hex or BCD definitions and later use the newly defined equivalents, should serve you.
 
Status
Not open for further replies.

Latest threads

Back
Top