Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Subject: C# .NET Write a program that takes a decimal value between 1 and 10 and

ID: 3866637 • Letter: S

Question

Subject: C# .NET

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.

This is what I have so far... I might've over complicated the if-else statement with the Switch selection statements. Also, I'm not sure how to call the romanNumeral class from the Program class.

Unfinished Code with errors:

namespace RomanNumerals

{
//Class to convert decimals to roman numerals
class romanNumeralConvert
{
public static void romanNumeral()
{
decimal number = 0;
  
if (number >= 1 && number <= 10)
{
switch (number)
{
case 1:
number = "I";
break;
case 2:
number = "II";
break;
case 3:
number = "III";
break;
case 4:
number = "IV";
break;
case 5:
number = "V";
break;
case 6:
number = "VI";
break;
case 7:
number = "VII";
break;
case 8:
number = "VIII";
break;
case 9:
number = "IX";
break;
default:
number = "X";
break;
}
}
else
{
number = "The Number entered must be between 1 and 10";
}
}
}


//Test class
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter a decimal value:"); // Prompt
decimal number = Convert.ToInt32(Console.ReadLine());
string numString = RomanNumerals.romanNumeralConvert.romanNumeral(number);

if (romanNumeralConvert.TryParse(numString, out number))
{
Console.WriteLine("The Roman Numeral is: " + number);
}
Console.ReadKey();

}

}
  
}

Explanation / Answer

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Chapater5PA1 { class Program { static void Main(string[] args) { int value; string roman; DisplayInstrution(); value = GetDecimal(); roman = CalculateRoman(value); DisplayResults(value, roman); Console.ReadKey(); } public static void DisplayInstrution() { Console.WriteLine("This application allows decimal value between 1 and 10"); Console.WriteLine("to be entered. It displays the equivalent roman numeral value."); Console.ReadKey(); } public static int GetDecimal() { int value; Console.WriteLine("Decimal value: "); value = Int32.Parse(Console.ReadLine()); return value; } public static string CalculateRoman(int value) { string result; if (value < 0 || value > 10) result = "Invalid input"; else if (value == 1) result = "I"; else if (value == 2) result = "II"; else if (value == 3) result = "III"; else if (value == 4) result = "IV"; else if (value == 5) result = "V"; else if (value == 6) result = "VI"; else if (value == 7) result = "VII"; else if (value == 8) result = "VIII"; else if (value == 9) result = "IX"; else result = "IX"; return result; } public static void DisplayResults(int value, string roman) { if (value != 0) { Console.WriteLine("Roman value: ", roman); } } } }