Saturday, May 22, 2010

Help with C# project please?

Honestly dont know what im doin,so any help is appreciated! Took out {} to make more space. Need to convert arabic to romal numerals. Its just a start...


class Program


static void Main(string[] args)


string s = Convert.ArabicToRoman(1);





class Convert


public static string ArabicToRoman(int number)


if (number %26lt; 0 || number %26gt; 3999)


throw new ArgumentException("Value must be in the range 0 - 3,999.");


if (number == 0) return "N";


int[] values = new int[]


1000, 900, 500, 400, 100,90, 50, 40, 10, 9, 5, 4, 1


};


string[] numerals = new string[]


"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"


};


StringBuilder result = new StringBuilder();


for (int i = 0; i %26lt; 13; i++)


while (number %26gt;= values[i])





number -= (number %26gt;= values[i])


result.Append(numerals[i]);

Help with C# project please?
Look, you need to figure out how many times your given number will go into a given number.





For example You need to figure out how many thousands will go into your number, and for each one, write out an 'M'





You can do this with the Div operator which will do an integer divide and ignore remainder. Then you use modulus to get the remainder to figure out what to use on the next number down the list.


No comments:

Post a Comment