Hello James,
Thursday August 28 1997, James Norman writes to Anyone:
JN> eg. put_roman(int num); which will display the roman
numeral
JN> depending on which integer (1-3999)
JN> get_roman(); which will read a roman numeral
JN> string, and return its integer value!!
JN> get_roman() MUST return 1 if invalid string code!! eg. IIV or IC, etc,
etc
And what should it return if given "I" as parameter?
If I remember well: I=1, V=5, X=10, L=50, C=100, D=500, M=1000
But how will we represent 5000? Normaly, it is V with a "-" on the TOP:
_
V
I let you decide and will use the var z in place
const z='?'
My idea:
1) decompose your int in a,b,c,d,... (with modulo operator) so that
num=a*1+b*5+c*10+d*50+e*100+f*500+g*1000
with a,c,e and g =0)
2) char string[40];
fill string with null characters (ASCII code 0)
3) for(short i=1;i<=g;i++) string[i-1]='M';
for (;i<=f;i++) string[i-1]='D';
and so on for e,d,c,...
Problem: For 4, this would write IIII instead of IV
so maybe:
if(a==4) {string[i-1]='I';string[i]='V';i+=2;a=0} else for-loop. Same thing
for c, e and g.
Problem: 99 would be written by XCIX, not IC
so:
if (d+c==5) /*d+c==5 d==1&&c==4*/ {...} else {d-for loop; if(c==4) {...}
else c-for loop}
etc
Hope this helps
Best regards,
Squirrel
--- FMail/Win32 1.22
(2:291/766.187)
---------------
* Origin: Marginal - Error in origin line! CTRL-ALT-DEL to res
|