settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: I need to write a program in C# that shows digits as words in English

+4 votes

I need to write a program in C# that asks for a digit (0-9), and depending on the input, shows the digit as a word (in English).

I need to print “not a digit” in case of invalid input. Also a switch statement must be used.

As an example:

d

result

2

two

1

one

0

zero

5

five

-0.1

not a digit

hi

not a digit

9

nine

10

not a digit

 

asked in C# category by user andrew

1 Answer

+1 vote
 
Best answer

Try this one:

using System;

class DigitAsWord
{
    static void Main()
    {
        Console.WriteLine("Please enter a number between 0 and 9:");
        string a = Console.ReadLine();

        switch (a)
        {
            case "0": Console.WriteLine("zero"); break;
            case "1": Console.WriteLine("one"); break;
            case "2": Console.WriteLine("two"); break;
            case "3": Console.WriteLine("three"); break;
            case "4": Console.WriteLine("four"); break;
            case "5": Console.WriteLine("five"); break;
            case "6": Console.WriteLine("six"); break;
            case "7": Console.WriteLine("seven"); break;
            case "8": Console.WriteLine("eight"); break;
            case "9": Console.WriteLine("nine"); break;
            default: Console.WriteLine("not a digit"); break;
        }
    }
}
answered by user samfred5830
selected by user golearnweb
...