View Full Version : Convert numeric value to roman numeral?
veghead05
05-04-2009, 02:15 PM
How do I convert a number into a roman numeral?
I have an assignment to ask the user to enter a number, then display that number as a roman numeral.
Where are the roman numerals?
HisWorld
05-04-2009, 11:59 PM
haha, its not as straight forward as you seem to think. you know the conversion right? 3 = III, 5 = V, 10 = X.
Well just off the top of my head you will need to read the user input and set whatever they input to a numeric veriable. then have a series of conditional statements "if-then, else" For each possible number you need to dispaly what you know is the equivalent roman numerial. ex. user inputs a five, you set that equal to a variable named "world.numbers" have maybe ten if statements that run,
"if world.numbers == 1
output I
else
...................
if world.number == 5
output 5
I would suggest you have the user only be allowed to input number's between 1 and some number like 10.
This can be down by using a while loop, "while both 0 < world.numbers <= 10"
Tell me if this helps
EricSkogen
05-05-2009, 02:01 AM
As far as I know, there are no "Roman Numeral" objects. You would have to use the Latin characters (http://en.wikipedia.org/wiki/Roman_numerals). output them just like you would any other text.
As far as the conversion goes, you could try the 1=I 2=II approach, but if you need to accept a large set (>20) perhaps this (http://www.moxlotus.alternatifs.eu/programmation-converter.html)would be more time efficient.
Scott300
05-06-2009, 12:10 AM
var number = 6 //test number
var times into 100 = 0 //if its 0 that means it cannot go into it do same for 50,5
var remainder after 100 = 0 // the remaining amount after its been divided do same for 50,5
bool 100 perfect = false // this tells us later if there is no remainder on the 100 do the same for 50,5
string finishednumber == "" // its blank for now, this is where we will write our finished digits to
if number can be divided by 100 in any way
{
times into 100 = number/100
remainder after 100 = remainder
if remainder after 100 == 0
{
100 perfect == true
}
}
//repeat for 50,5
if times into 100 > 0
{
loop times=times into 100
{
finishednumber = X.finishednumber
}
}
and so on you need to make sure you put the remainders in there also I am getting tired of writing this its a pain in the ass tbh if you really need this finished send me a pm ill help you with it =)
veghead05
05-12-2009, 05:44 PM
I'm actually really confused by ur post scott, could you explain what you are doing there? The comments helped a little but I'm still lost.
Scott300
05-12-2009, 08:18 PM
I'm actually really confused by ur post scott, could you explain what you are doing there? The comments helped a little but I'm still lost.
Tonight ill try and work it out in Alice instead of my head and post my findings.
Scott300
05-13-2009, 12:59 PM
OK, this works about 90% try like 122 for an example number. It has trouble converting any number that has 50 in it (ex- 151). But other than that it works great!