Questions tagged [roman-numerals]

The Roman numeral system is an ancient way of representing numbers. The base symbols are I (1), V (5), X (10), L (50), C (100), D (500) and M (1000).

Roman numerals on Wikipedia

273 questions
-1
votes
1 answer

Need help writing an int to roman numeral converter using only if, if else, and switch statements

Here is the code: public String ToRoman(int number) { if ((number < 1 || (number > 3999))) if (number >= 1000) return "M" + ToRoman(number - 1000); if (number >= 900) return "CM" + ToRoman(number - 900); if (number…
user2840309
  • 1
  • 1
  • 1
-2
votes
2 answers

I was doing this question Roman numerals, i don't understand exactly what I did wrong or how to solve this, can someone please explain this to me?

I was expecting 3 when entering III but I keep on getting 1 and the funny thing is i think it is only happening with a combination of the same roman letters because II is giving me back 2 like i wanted LVIII is giving me 56 instead of 58, but…
WeirdPanda
  • 13
  • 1
-2
votes
2 answers

Why does the if/else if approach give a wrong answer for the Roman To integer conversion question? This is a question from leetcode

This is the question that I am referring to: https://leetcode.com/problems/roman-to-integer/ And this is the code that I have used for the following: int romanToDecimal(string &str) { int num=0; for(int i=0; i
-2
votes
1 answer

Roman numerical generator

I was trying to come up with a roman numerical generator in Javascript and I found this on Stack Overflow. I passes all tests but I cannot figure out how it works. I would really appreciate a nice description what is going on in this code: let…
Harry_C
  • 179
  • 1
  • 1
  • 14
-2
votes
1 answer

C program to display Roman numeral till n

I made up this problem for myself. This code prints integer numbers up to n in Romans. The code works fine. Is there any way to make it shorter and more efficient? Also, point out any mistakes made. #include void roman(int num) { …
pexeixv
  • 89
  • 7
-2
votes
3 answers

Conversion of integers to Roman numerals (python)

I understand there were many similar questions being asked on this topic. But I still have some doubts need to be clear. def int_to_roman(input): if type(input) != type(1): raise TypeError, "expected integer, got %s" % type(input) …
tby
  • 17
  • 1
  • 1
  • 4
-2
votes
2 answers

Roman numbers to letters

How can I translate or process a roman number to a decimal number in words and vice versa? I want to do this in C. The idea is to get the number or the letters and process it. Here is an example: MDXXIII = One thousand five hundred and…
fullmoon
  • 25
  • 5
-2
votes
1 answer

check for the validity of a roman number (difficult)

I want to write a function to check if a given string in roman presentation is correct or not. They are a lot of cases of non allowed combinations : (I assume that the given string will represent a number between 1 and 3999) We can't have the same…
salamanka44
  • 904
  • 3
  • 17
  • 36
-2
votes
3 answers

Having Trouble Converting Roman Numeral to Integer in Python

Not quite sure what I'm doing wrong. Using Python 3.2 Get the issue: TypeError: list indices must be integers, not list Here's my code. print('Please input your first Roman Numeral.') ri1 = input() def romantointeger(x): conversion =…
-3
votes
1 answer

converting roman numerals to integer- unclear about variables in leetcode question 13 solution

I know s is the string of roman numerals but because I don't know what i stand for, I am not sure what s[i] means. I am trying to understand the solution that is posted line by line, but am stuck with this specific part. All help is appreciated, I…
-3
votes
2 answers

Can someone explain me this code

I need an explanation for this tiny java code. decimalNumber is a variable for user input and M for roman numeral 1000 This is a part of a roman numeral converter: m = decimalNumber / 1000; decimalNumber = decimalNumber % 1000;
F. Pajic
  • 41
  • 6
-3
votes
2 answers

Checking Errors of Roman Numerals Given A Set of Rules

So for my comp sci class I was tasked with adding, subtracting, dividing, and multiplying Roman Numerals if they pass 12 rules that I have been given. I created a 13 element boolean array to keep track of which rules were broken. I created a…
Zack Sloan
  • 133
  • 1
  • 1
  • 8
-3
votes
3 answers

Why does this JavaScript switch statement (which is inside a for loop) keep it's values from a previous iteration?

function convertToRoman(num) { //seperate the number in to singular digits which are strings and pass to array. var array = ("" + num).split(""), arrayLength = array.length, romStr = ""; //Convert the strings in the array to…
Tom
  • 4,776
  • 2
  • 38
  • 50
-3
votes
1 answer

Integer to Roman Numeral. I dont understand how to call the methods back to main. i am stuck here and need some assistance

public static void main(String[] args) { // Given a Scanner as input, prompts the user to input a number between 1 and 3999. // Checks to make sure the number is within range, and provides an error message until // the user provides a value…
osubucs28
  • 17
  • 4
-3
votes
1 answer

C++ Roman Numeral Converter output from?

So this program is supposed to output to the console "Enter a negative number to end. Enter an arabic number between 1 and 3999:" then you give it your number, it breaks it down and converts it. I am getting output that looks like this 1 9 8 4 and…
1 2 3
18
19