-2

whatever the input is it should print the answer in words(no limits) For example input is 2 it should answer in words "TWO" few more examples to understand 12 = "twelve" ,51 = "fifty one", 1000 = "One thousand",2005 = "two thousand and five" and so on...

  • @dustmouse no not yet... i am confused really even how to start... – Muhammad Saad Haris Oct 17 '15 at 05:21
  • old task for student? – alerya Oct 17 '15 at 05:22
  • Follow this: http://stackoverflow.com/questions/3213/convert-integers-to-written-numbers or http://www.codeproject.com/Articles/15934/How-to-Convert-a-Numeric-Value-or-Currency-to-Engl or http://www.blackbeltcoder.com/Articles/strings/converting-numbers-to-words – autopilot Oct 17 '15 at 05:22
  • http://stackoverflow.com/questions/2729752/converting-numbers-in-to-words-c-sharp – alerya Oct 17 '15 at 05:22
  • Possible duplicate of [How can I convert an integer into its verbal representation?](http://stackoverflow.com/questions/554314/how-can-i-convert-an-integer-into-its-verbal-representation) – Evan Trimboli Oct 17 '15 at 08:38

2 Answers2

0

Check out great Humanizer project. It has exactly what you need.

3501.ToWords() => "three thousand five hundred and one"
Aleksey L.
  • 35,047
  • 10
  • 74
  • 84
0
Try this approach:
It's not a complete code, you can improve it by recursive call with
proper range checking etc.

Create a function with input parameter range from 0 to 99 (as shown below):
private string DigitToTextConverter(int digit)
    {
        string digitText = "";
        switch (digit)
        {
            case 0:
                digitText = "zero";
                break;
            case 1:
                digitText = "one ";
                break;
            case 2:
                digitText = "two ";
                break;
            case 3:
                digitText = "three ";
                break;
            case 4:
                digitText = "four ";
                break;
            case 5:
                digitText = "five ";
                break;
            case 6:
                digitText = "six ";
                break;
            case 7:
                digitText = "seven ";
                break;
            case 8:
                digitText = "eight ";
                break;
            case 9:
               .....;
            case 10:
               .....
            case 99:
               .....
            default:
                break;
        }

        return digitText;
    } 

//Call this function with appropriate parameter: (suppose user entered 1234)

 var userInput = 1234;
 var digitText = new StringBuilder();

 var quotient = userInput / 1000;
 string convertedText = DigitToTextConverter(quotient);
 digitText.Append(convertedText + " thousand");
 digitText.AppendFormat(" ");
 var remainder = userInput % 1000;

 quotient = remainder / 100;
 convertedText = DigitToTextConverter(quotient);
 digitText.Append(convertedText + " thundred");
 digitText.AppendFormat(" ");
 remainder = remainder % 100;

 //Complete remaining portion, better to have a function with recursive call
 string finalText = digitText.ToString();
Sudipta Kumar Maiti
  • 1,669
  • 1
  • 12
  • 18