http://cur.lv/4x9e0 (Earn Bitcoins) /* * Write a program that converts a number in the range [0...999] to a text corresponding to its English pronunciation. Examples: 0 -> "Zero" 273 -> "Two hundred seventy three" 400 -> "Four hundred" 501 -> "Five hundred and one" 711 -> "Seven hundred and eleven" */ using System; class NumberToText { static void Main(string[] args) { Console.Write("Enter a number between [1..999]: "); int number = int.Parse(Console.ReadLine()); string textNumber = ""; int digits = number % 10; int tens = number % 100; int hundreds = number / 100; if (hundreds != 0) { switch (hundreds) { case 1: textNumber += "One hundred "; break; case 2: textNumber += "Two hundred "; break; case 3: textNumber += "Three hundred "; break; case 4: textNumber += "Four hundred "; break; case 5: textNumber += "Five hundred "; break; case 6: textNumber += "Six hundred "; break; case 7: textNumber += "Seven hundred "; break; case 8: textNumber += "Eight hundred "; break; case 9: textNumber += "Nine hundred "; break; } if (tens / 10 == 0 && digits != 0) { textNumber += "and "; switch (digits) { case 0: textNumber += "zero"; break; case 1: textNumber += "one"; break; case 2: textNumber += "two"; break; case 3: textNumber += "three"; break; case 4: textNumber += "four"; break; case 5: textNumber += "five"; break; case 6: textNumber += "six"; break; case 7: textNumber += "seven"; break; case 8: textNumber += "eight"; break; case 9: textNumber += "nine"; break; } } } if (tens < 20) { switch (tens) { case 10: textNumber += "ten"; break; case 11: textNumber += "eleven"; break; case 12: textNumber += "twelve"; break; case 13: textNumber += "thirteen"; break; case 14: textNumber += "fourteen"; break; case 15: textNumber += "fifteen"; break; case 16: textNumber += "sixteen"; break; case 17: textNumber += "seventeen"; break; case 18: textNumber += "eighteen"; break; case 19: textNumber += "nineteen"; break; } } else { switch (tens / 10) { case 2: textNumber += "twenty "; break; case 3: textNumber += "thirty "; break; case 4: textNumber += "fourty "; break; case 5: textNumber += "fifty "; break; case 6: textNumber += "sixty "; break; case 7: textNumber += "seventy "; break; case 8: textNumber += "eigthy "; break; case 9: textNumber += "ninety "; break; } if (digits != 0) { switch (digits) { case 0: textNumber += "zero"; break; case 1: textNumber += "one"; break; case 2: textNumber += "two"; break; case 3: textNumber += "three"; break; case 4: textNumber += "four"; break; case 5: textNumber += "five"; break; case 6: textNumber += "six"; break; case 7: textNumber += "seven"; break; case 8: textNumber += "eight"; break; case 9: textNumber += "nine"; break; } } } if (hundreds == 0 && tens/10 == 0) { switch (digits) { case 0: textNumber += "zero"; break; case 1: textNumber += "one"; break; case 2: textNumber += "two"; break; case 3: textNumber += "three"; break; case 4: textNumber += "four"; break; case 5: textNumber += "five"; break; case 6: textNumber += "six"; break; case 7: textNumber += "seven"; break; case 8: textNumber += "eight"; break; case 9: textNumber += "nine"; break; } } Console.WriteLine("{0} -> {1}", number, textNumber); } }