Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: Vision on March 03, 2004, 02:03 PM

Title: Decimal to Roman Numeral Convertor
Post by: Vision on March 03, 2004, 02:03 PM
Im in c++ class right now and we need to write a program that you input a number and it outputs the number in Roman numerals can someone give me an idea for wat to use because i havent been to school to find out how were suppost to and the teachers gay and wont tell me...
Title: Re:Decimal to Roman Numeral Convertor
Post by: Eibro on March 03, 2004, 03:22 PM
Something that immediatly comes to mind:

std::string returnString;

const long rnChars[] = { 'M', 'D', 'C', 'L', 'X', 'V', 'I' };
const long rnDigits[] = { 1000, 500, 100, 50, 10, 5, 1, 0 };

for ( long i = 0; i < rnDigits[i] != 0; ++i )
{
  long quotient = input / rnDigits[i];
  long remainder = input % rnDigits[i];
   
  returnString.append( quotient,  rnChars[i] );
  input = remainder;
}
The above will *not* work. It should at least get you started. Basically, you'll want to keep extracting digits and dividing to figure out how many multiples of each letter to add.
Title: Re:Decimal to Roman Numeral Convertor
Post by: Vision on March 04, 2004, 09:21 PM
thnx :) anymore suggestions?
Title: Re:Decimal to Roman Numeral Convertor
Post by: Mephisto on March 04, 2004, 09:59 PM
You should just do this by yourself.  :P

I've written one of these along time ago.  I'll post the source if you find you desperately need it.  :P  But it's rather simple, just a matter of logic more or less.