Advertisement
nmnikolov

08. DigitAsWord

Jun 29th, 2014
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that asks for a digit (0-9), and depending on the input, shows the digit as a word (in English). Print “not a digit” in case of invalid inut. Use a switch statement. Examples:
  4. // |    d | result      |
  5. // |    2 | two         |
  6. // |    1 | one         |
  7. // |    0 | zero        |
  8. // |    5 | five        |
  9. // | -0.1 | not a digit |
  10. // |   hi | not a digit |
  11. // |    9 | nine        |
  12. // |   10 | not a digit |
  13.  
  14. class DigitAsWord
  15. {
  16.     static void Main()
  17.     {
  18.         try
  19.         {
  20.             byte digit = byte.Parse(Console.ReadLine());
  21.             switch (digit)
  22.             {
  23.                 case 0:
  24.                     Console.WriteLine("zero"); break;
  25.                 case 1:
  26.                     Console.WriteLine("one"); break;
  27.                 case 2:
  28.                     Console.WriteLine("two"); break;
  29.                 case 3:
  30.                     Console.WriteLine("three"); break;
  31.                 case 4:
  32.                     Console.WriteLine("four"); break;
  33.                 case 5:
  34.                     Console.WriteLine("five"); break;
  35.                 case 6:
  36.                     Console.WriteLine("six"); break;
  37.                 case 7:
  38.                     Console.WriteLine("seven"); break;
  39.                 case 8:
  40.                     Console.WriteLine("eight"); break;
  41.                 case 9:
  42.                     Console.WriteLine("nine"); break;
  43.                 default:
  44.                     Console.WriteLine("not a digit"); break;
  45.             }
  46.         }
  47.         catch (Exception)
  48.         {
  49.             Console.WriteLine("not a digit"); ;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement