Hello!
Do anyone know optimal solution for roman numerals to 100?
I made a program just for numerals to 10, but I have no idea how to solve it to 100 optimally cuz if statements are not a very good solution.
static void Main(string[] args)
{
int number;
bool checkValue;
Console.Write("Enter the number between 1 and 10: ");
checkValue = int.TryParse(Console.ReadLine(), out number);
if (checkValue)
{
if (number > 1 && number < 10)
{
if (number == 1)
{
Console.WriteLine("I");
}
else if (number == 2)
{
Console.WriteLine("II");
}
else if (number == 3)
{
Console.WriteLine("III");
}
else if (number == 4)
{
Console.WriteLine("IV");
}
else if (number == 5)
{
Console.WriteLine("V");
}
else if (number == 6)
{
Console.WriteLine("VI");
}
else if (number == 7)
{
Console.WriteLine("VII");
}
else if (number == 8)
{
Console.WriteLine("VIII");
}
else if (number == 9)
{
Console.WriteLine("IX");
}
else if (number == 10)
{
Console.WriteLine("X");
}
}
else
{
Console.WriteLine("\nERROR! Entered number must be between 1 and 10.");
}
}
else
{
Console.WriteLine("\nERROR! Entered value must be a number.");
}
Console.ReadKey();
}
Any help is the most welcome! ;)