Advertisement
sylviapsh

Last Digit Of an Integer Number As English Word

Jan 21st, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2.  
  3. class LastDigitOfIntAsEnglishWord
  4. {
  5.   static string DigitAsEnglishWord(string digit)
  6.   {
  7.     string lastDigit = digit.Substring(digit.Length-1, 1);//Get the last symbol in the string by making a sustring from the last position
  8.  
  9.     switch (lastDigit)//Switch the cases
  10.     {
  11.       case "0": { digit = "zero"; } break;
  12.       case "1": { digit = "one"; } break;
  13.       case "2": { digit = "two"; } break;
  14.       case "3": { digit = "three"; } break;
  15.       case "4": { digit = "four"; } break;
  16.       case "5": { digit = "five"; } break;
  17.       case "6": { digit = "six"; } break;
  18.       case "7": { digit = "seven"; } break;
  19.       case "8": { digit = "eight"; } break;
  20.       case "9": { digit = "nine"; } break;
  21.       default: { digit = "Not a digit!"; } break;//If the symbol isn't a digit, print a warning.
  22.     }
  23.     return digit;
  24.   }
  25.   static void Main()
  26.   {
  27.     Console.Write("Please enter an integer number:");
  28.     string inputNum = Console.ReadLine();
  29.  
  30.     string result = DigitAsEnglishWord(inputNum);
  31.     Console.WriteLine(result);
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement