Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Number_as_Words
- {
- class MainClass
- {
- static string ContainerOfNumbers(string pointer)
- {
- string convert = "error";
- switch (pointer)
- {
- case "0": convert = "zero";
- break;
- case "1": convert = "one";
- break;
- case "2": convert = "two";
- break;
- case "3": convert = "three";
- break;
- case "4": convert = "four";
- break;
- case "5": convert = "five";
- break;
- case "6": convert = "six";
- break;
- case "7": convert = "seven";
- break;
- case "8": convert = "eight";
- break;
- case "9": convert = "nine";
- break;
- case "10": convert = "ten";
- break;
- case "11": convert = "eleven";
- break;
- case "12": convert = "twelve";
- break;
- case "13": convert = "thirteen";
- break;
- case "14": convert = "fourteen";
- break;
- case "15": convert = "fifteen";
- break;
- case "16": convert = "sixteen";
- break;
- case "17": convert = "seventeen";
- break;
- case "18": convert = "eighteen";
- break;
- case "19": convert = "nineteen";
- break;
- case "20": convert = "twenty";
- break;
- case "30": convert = "thirty";
- break;
- case "40": convert = "forty";
- break;
- case "50": convert = "fivty";
- break;
- case "60": convert = "sixty";
- break;
- case "70": convert = "seventy";
- break;
- case "80": convert = "eighty";
- break;
- case "90": convert = "ninety";
- break;
- }
- return convert;
- }
- public static void Main(string[] args)
- {
- Console.Write("Write number in the range [0…999]: ");
- string number = Console.ReadLine();
- int length = number.Length;
- string result = "error";
- if (length == 1)
- {
- string pointer = char.ToString(number[0]);
- result = ContainerOfNumbers(pointer);
- }
- else if (length == 2)
- {
- string pointer = number[0] + "0";
- string firstDigit = ContainerOfNumbers(pointer);
- pointer = char.ToString(number[1]);
- string secondDigit = ContainerOfNumbers(pointer);
- result = firstDigit + secondDigit;
- }
- else if (length == 3)
- {
- string pointer = char.ToString(number[0]);
- string firstDigit = ContainerOfNumbers(pointer);
- pointer = number[1] + "0";
- string secondDigit = ContainerOfNumbers(pointer);
- pointer = char.ToString(number[2]);
- string thirdDigit = ContainerOfNumbers(pointer);
- result = firstDigit + "hundred and " + secondDigit + thirdDigit;
- }
- else
- {
- Console.WriteLine("error");
- }
- string ConvertFirstToUppercase = char.ToUpper(result[0]) + result.Substring(1);
- Console.WriteLine(ConvertFirstToUppercase);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement