public static void Main()
Console.WriteLine("\nEnter '0' to quit the program at any time\n");
Console.Write("Enter number: ");
input = Console.ReadLine();
isValid = int.TryParse(input, out number);
Console.WriteLine("\n Not an integer, please try again\n");
Console.WriteLine("\n {0}\n", NumberToText(number, isUK));
while (!(isValid && number == 0));
Console.WriteLine("\nProgram ended");
public static string NumberToText(int number, bool isUK)
if (number == 0) return "Zero";
string and = isUK ? "and " : "";
if (number == -2147483648) return "Minus Two Billion One Hundred " + and +
"Forty Seven Million Four Hundred " + and + "Eighty Three Thousand " +
"Six Hundred " + and + "Forty Eight";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string[] words0 = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine "};
string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "};
string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "};
string[] words3 = { "Thousand ", "Million ", "Billion " };
num[2] = number / 1000000;
num[1] = num[1] - 1000 * num[2];
num[3] = number / 1000000000;
num[2] = num[2] - 1000 * num[3];
for (int i = 3; i > 0; i--)
for (int i = first; i >= 0; i--)
if (num[i] == 0) continue;
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (h > 0 || i < first) sb.Append(and);
sb.Append(words2[t - 2] + words0[u]);
if (i != 0) sb.Append(words3[i - 1]);
return sb.ToString().TrimEnd();