I have a problem in these code as the error message show that the m1 and 2 is unassigned local variables
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter th number ");
int x= int.Parse(Console.ReadLine());
RomNo(x);
Console.ReadLine();
}
static void RomNo(int n)
{
while (n != 0)
{
int s = 100;
int r = n / s;
n %= s;
string m, m1, m2;
switch (s)
{
case 1:
m = "I";
m1 = "V";
m2 = "X";
break;
case 10:
m = "X";
m1 = "L";
m2 = "C";
break;
case 100:
m = "C";
m1 = "D";
m2 = "M";
break;
default:
m = "M";
break;
}
for (int i = 1; i < r; i++)
{
if (s == 1000)
if (r == 9)
{
Console.Write(m+m2);
break;
}
if (r == 4)
{
Console.Write(m+m1);
break;
}
if (r >= 5 && i < 5)
{
Console.Write(m1);
i += 4;
}
else
Console.Write(m);
}
}
return;
}
}
}