Not Yet Answered # Convert numbers [dec - rom]

Discussion Starter regist1 -1 gerard4143 371 Discussion Starter regist1 -1 gerard4143 371 Discussion Starter regist1 -1 jonsca 1,059 Discussion Starter regist1 -1 jonsca 1,059 Discussion Starter regist1 -1 jonsca 1,059 jonsca 1,059 Discussion Starter regist1 -1 mvmalderen 2,072

-3

I would be most grateful if you could post/write a code for me, please.

I really need it, either convert decimal to roman or roman to decimal.

Thanks.

0

I would be most grateful if you could post/write a code for me, please.

I really need it, either convert decimal to roman or roman to decimal.Thanks.

Please read:

-1

Yes, of course I accept that.. but I'm just learning C and I'm in a bad situation now (no time), so if someone could help me.. it will be great.

anyway, I'm trying to write it alone.. :(

1

Yes, of course I accept that.. but I'm just learning C and I'm in a bad situation now (no time), so if someone could help me.. it will be great.

anyway, I'm trying to write it alone.. :(

The best thing you could do is post what you have so far and state where your having problems....

0

well, my problem is to find algorithm.. could you help me at least with the way I can white it (in C), just algorithm, some advices please..

0

You are not the first person that has posted here to deal with this problem. Do a search on the forums.

Hint, break the number that is input into pieces, going from largest to smallest. You probably know those pieces well, or if you don't look the system up on Wikipedia, it's a nice article.

0

Hint, break the number that is input into pieces, going from largest to smallest. You probably know those pieces well, or if ...

Something like this? (decimal to roman)

```
while (number >= 1000)
{
printf("M");
number -= 1000;
}
```

But I still dont understand how it works..

for example, I've got 595 (DXCV?) and how can I get roman number from it? ..

0

I've seen stuff with people putting a bar over it for multiple thousands, so V (bar) = 5000.

With your example of 595, how many thousands are in it? none, remainder 595, how many 500s are in it, 1, remainder 95. So we have D. Here's where it's a little tricky, but seems they only put the C if it's 100 before 1000, so 950 is not LM, it's CML (50 above 100 before 1000). So for numbers less than 100 we put if it's 10 less and put the remainder on the other side. 95 is between 90 and 100 with a remainder of 5. So we get XCV.

So subtraction and modulus (%) are your friends along with making some if statements for the trickier exceptions.

0

Yes, I've got it.. convert from decimal to roman is okey, I just compare my input number(decimal) and then print it according to roman numbers.. - Thank you!

And what if I want it reversly.. my input will be a roman nubmer and I need to convert it into decimal.. Do I need some array for it (for M - 1000) or what?

0

Look for numbers out of their size order. You could use a switch statment for the conversion and then add or subtract as needed. For example MCM: C is less than M could be 1100, but look ahead to the next one M, ok so we know it's going to be 1000 + (1000-100) we know that we were 100 before 1000 so there isn't going to be any 500 (since adding a D would just make it 2400 or MMCD). Count the hundreds and subtract for any XC type situations.

0

You've come pretty far with the first part, why don't you see what you can come up with. You were right, you probably want to read the number into a char array. Like you said you probably want to use a switch block to match Roman numeral to regular number. You might put that into a function. Take an example, like MCMXLVIII which has a few of the complications we talked about and write that as a "worst case." Go through your idea step by step on a piece of paper. Code it. Then after you've got that down test it with some of the simpler cases to see if you've overgeneralized it.

*Edited 6 Years Ago by jonsca*: n/a

0

I'm lost.. I have no idea

1

I'm lost.. I have no idea

I once did a conversion from roman to decimal using the following approach:

- I created a function to translate every roman symbol:
`M, D, C, L, X, V, I`

to its decimal equivalent. - I let my program read the roman number into a character array (aka: c-string).
- Then I used a loop to iterate through every 'character' of the roman number.
- (inside the loop) You always get the decimal equivalent of the current character and the next one, you compare them to each other, if the next one is bigger, then subtract its value from the value inside the variable you're going to use to store the decimal equivalent of the roman number.

If it's not, then you just add it. - Once you've implemented the previous things, you can (eventually) start thinking up a way to validate the input to avoid that the user inputs any invalid data.

Hope this helps.

*Edited 6 Years Ago by mvmalderen*: n/a

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I ...

Hello All ...

Iam Getting An Error With try to excecute the stored procedure .

I have Have Sql database , the stored procedure like so :

```
USE [MPRS]
GO
/****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE ...
```

I don’t want at this stage work on a big separate project as I've already got plenty ...