number conversion to roman numeral

how to convert numbers 1-2000 to roman numerals?

Page 1 of 1

3 Replies - 7620 Views - Last Post: 03 August 2009 - 06:02 PM Rate Topic: -----

#1 rebellion214  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 Arenlor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 34
  • View blog
  • Posts: 389
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 kidicarus  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1