Advertisement
striking

Numbers In Word

Feb 4th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System;
  2.  
  3. class NumberInWords
  4. {
  5. static void Main(string[] args)
  6. {
  7. string input = Console.ReadLine();
  8. int number = int.Parse(input);
  9.  
  10. string[] numberUnits = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
  11. "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
  12. string[] numberTenths = { "", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty" };
  13. string hundred = "hundred";
  14.  
  15. if (number >= 0 && number <= 19)
  16. {
  17. Console.WriteLine(numberUnits[number]);
  18. }
  19.  
  20. else if (number >= 20 && number <= 99)
  21. {
  22. if (input[1] != '0')
  23. {
  24. Console.WriteLine(numberTenths[int.Parse(input[0].ToString())] + " " + numberUnits[int.Parse(input[1].ToString())]);
  25. }
  26. else
  27. {
  28. Console.WriteLine(numberTenths[int.Parse(input[0].ToString())]);
  29. }
  30. }
  31.  
  32. else
  33. {
  34. int lastTwoDigits = 0;
  35. string lastTwoStrings = "";
  36. if (input[0] == '1')
  37. {
  38. if (input[1] == '1')
  39. {
  40. lastTwoStrings += input[1];
  41. lastTwoStrings += input[2];
  42. lastTwoDigits = int.Parse(lastTwoStrings);
  43. Console.WriteLine("One {0} and {1}", hundred, numberUnits[lastTwoDigits]);
  44. }
  45. else if (input[1] == '0' && input[2] != '0')
  46. {
  47. Console.WriteLine("One {0} and {1}", hundred, numberUnits[int.Parse(input[2].ToString())]);
  48. }
  49. else if (input[1] != '0' && input[2] != '0')
  50. {
  51. Console.WriteLine("One {0} and {1} {2}", hundred, numberTenths[int.Parse(input[1].ToString())],
  52. numberUnits[int.Parse(input[2].ToString())]);
  53. }
  54. else if (input[1] != '0' && input [2] == '0')
  55. {
  56. Console.WriteLine("One {0} and {1}", hundred, numberTenths[int.Parse(input[1].ToString())]);
  57. }
  58. else
  59. {
  60. Console.WriteLine("One {0}", hundred);
  61. }
  62. }
  63.  
  64. else
  65. {
  66. if (input[1] == '1')
  67. {
  68. lastTwoStrings += input[1];
  69. lastTwoStrings += input[2];
  70. lastTwoDigits = int.Parse(lastTwoStrings);
  71. Console.WriteLine("{0} {1} and {2}", numberUnits[int.Parse(input[0].ToString())], hundred, numberUnits[lastTwoDigits]);
  72. }
  73. else if (input[1] != '1' && input[2] == '0')
  74. {
  75. Console.WriteLine("{0} {1} and {2}", numberUnits[int.Parse(input[0].ToString())], hundred,
  76. numberTenths[int.Parse(input[1].ToString())]);
  77. }
  78. else
  79. {
  80. Console.WriteLine("{0} {1} and {2} {3}", numberUnits[int.Parse(input[0].ToString())], hundred,
  81. numberTenths[int.Parse(input[1].ToString())], numberUnits[int.Parse(input[2].ToString())]);
  82. }
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement