# number conversion to roman numeral

Page 1 of 1

## 3 Replies - 9325 Views - Last Post: 03 August 2009 - 06:02 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=118242&amp;s=c472ff4fbcc75d723d8f31e120b38d2a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rebellion214

Reputation: 0
• Posts: 1
• Joined: 03-August 09

# number conversion to roman numeral

Posted 03 August 2009 - 07:20 AM

hey guys im a newbie c++ programmer

i wanted to know how to convert numbers 1-2000 into roman numerals.

i started out on this code but cant figure the rest of it.. can you please help me :C

``` #include<iostream.h>
#include<conio.h>
int main()
{clrscr ();

int r;

cout<<"roman numerals 1- 2000";
cout<<endl;

for(r=1; r<=2000;r++)

```

i was trying to make it loop to 2000 and convert each number to its roman numeral, but i cant get the right logic and program to convert it to the right roman numerals.

i tried this logic

``` if (r>=1000)
{cout<<"M";
n=n-1000;
}
if else (r>=1000)
{cout<<"M";
n=n-1000;
}

if else (r>=500)
{cout<<"D";
n=n-500;
}

etc...
```

but i forgot about the numbers 999 or 90 because if i used my own logic, it would display number 1900 to MDCC, which is wrong because it's supposed to be CM. please help me

*** MOD EDIT: Fixed code tags ***

Is This A Good Question/Topic? 0

## Replies To: number conversion to roman numeral

### #2 wildgoose

• D.I.C Regular

Reputation: 67
• Posts: 468
• Joined: 29-June 09

## Re: number conversion to roman numeral

Posted 03 August 2009 - 07:56 AM

You're burying yourself early in the problem.
Don't put a loop. Put in a single number then solve it. Change the number a few times and once you think you have it working, then print out your 2000 numbers!

Work your problem out on paper first! Remember that converting numbers to roman numbers is a process of Roman Numeral thresholds, plus negative offsets!

insert code within brackets []
```
```
followed by /code within brackets.

This post has been edited by wildgoose: 03 August 2009 - 07:59 AM

### #3 Arenlor

• D.I.C Regular

Reputation: 36
• Posts: 414
• Joined: 26-April 06

## Re: number conversion to roman numeral

Posted 03 August 2009 - 04:47 PM

Please solve this: 2000 % 1000. Then solve 1500 % 1000. That's how I would start on it.

### #4 kidicarus

Reputation: 16
• Posts: 139
• Joined: 13-February 09

## Re: number conversion to roman numeral

Posted 03 August 2009 - 06:02 PM

Yes. I would get the number of "1000" to use. I would get the number of 100's to use. I would get the number of 10's to use. And then I would write equivalent roman numerals for this, designing it how you please.

For example:
XIIII
or XIV
for 14.