Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a program that takes a decimal value between 1 and 10 and displays its equivalent Roman numeral value. Display an error message if the value entered is outside of the acceptable range. Write a two class solution. The second class should allow the user to input a test value.

What I have tried:

I don't seem to understand what to actually do.
Posted
Updated 16-May-21 20:53pm

I wonder if someone, in the web, did understand such requirements...
convert number to roman numeral program example - Google Search[^]
 
Share this answer
 
Quote:
Write a program that takes a decimal value between 1 and 10 and displays its equivalent Roman numeral value.

This means that:
Input -> Result
1 -> I
2 -> II
3 -> III
4 -> IV
5 -> V
6 -> VI
7 -> VII
8 -> VIII
9 -> IX
 
Share this answer
 
Roman numbers aren't difficult, and this is a relatively simple problem that is given as homework to tens of thousands of students every year.
In this case it's trivial because you only have to deal with ten values:
 1    I
 2   II
 3  III
 4   IV
 5    V
 6   VI
 7  VII
 8 VIII
 9   IX
10    X

So, start by reading this: How to Write Code to Solve a Problem, A Beginner's Guide[^] and then think about what you have done in previous exercises.

I'm pretty sure you have read input from the user before, converted it to a number, done some processing on it, and printed the result - so there is the basis for your app:
C#
public static void Main()
    {
    int value = Input.GetInteger("Enter value to convert to Roman Numerals (1 to 10 only)", 1, 10);
    string roman = ConvertToRoman(value);
    Console.WriteLine($"{value} is {roman} in Roman Numerals");
    }
private static string ConvertToRoman(int value)
    {
    ...
    }
...
public static class Input
    {
    public static int GetInteger(string prompt, int min, int max)
        {
        ...
        }
    }
Now all you have to do is "fill in the blanks" and write two very simple methods.
Hint: GetInteger will want a loop that reports problems until the user enters a valid number between the min and max, and you might want to look at the TryParse methods to convert the input to a number (Google will help you there).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900