if you stare at -> https://i.pinimg.com/736x/54/59/a9/5459a94e8ac5ac75341780952fca954e--roman-numeral--romans.jpg
long enough, you notice a pattern.
I = 1
II = 2
III = 3
IIII != 4 ?!
V = 5
VI = 6
VII = 7
VIII = 8
VIIII != 9 ?!
X = 10
so now you can model that pattern with the right checks and recursion.
//PSEUDO CODE
1 2 3 4 5 6 7 8
|
if
(number >= 4)
{
return composition + (number >= 5) "V" + recursion(decrease number by 5)
: "IV" + recursion(decrease number by 4);
}
while (number > 0) { composition += "I"; number--; }
| |
so if I input 3, the if check fail and the while loop build a string of "III"
if I input 4, the if succed, the second case of the ternary operator is choosen, my string become "IV", number become 0 and the while add nothing to it
if I input 7, the if will pick up the "V", and the 2 remaining digits will be handled by the while in the recursive call
so you would have a similar case above the 4, checking for 9 and 10, then one more above checking for 40 and 50 and so on for the other "breaking points" where the symbols change
For this to work though, you also need to know about recursion :)