Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace NumWords
  6. {
  7. class Program
  8. {
  9.  
  10. static String NumWords(double n)
  11. {
  12. string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven",
  13. "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
  14. "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  15. string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty",
  16. "sixty", "seventy", "eighty", "ninty" };
  17. string[] suffixesArr = new string[] { "thousand" };
  18. string words = "";
  19.  
  20. bool tens = false;
  21.  
  22. if (n > 3000)
  23. {
  24. Console.WriteLine("o p s tama na sobra na");
  25. Console.ReadLine();
  26. Environment.Exit(0);
  27. }
  28. if (n == 0) {
  29. Console.WriteLine("zero");
  30. Console.ReadLine();
  31. Environment.Exit(0);
  32. }
  33. if (n >= 1000)
  34. {
  35. if (n % 1000 > 0) words += NumWords(Math.Floor(n / 1000)) + " thousand, ";
  36. else words += NumWords(Math.Floor(n / 1000)) + " thousand";
  37. n %= 1000;
  38. }
  39. if (0 <= n && n <= 999)
  40. {
  41. if ((int)n / 100 > 0)
  42. {
  43. words += NumWords(Math.Floor(n / 100)) + " hundred";
  44. n %= 100;
  45. }
  46. if ((int)n / 10 > 1)
  47. {
  48. if (words != "")
  49. words += " ";
  50. words += tensArr[(int)n / 10 - 2];
  51. tens = true;
  52. n %= 10;
  53. }
  54.  
  55.  
  56. if (n < 20 && n > 0)
  57. {
  58. if (words != "" && tens == false)
  59. words += " ";
  60. words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
  61. n -= Math.Floor(n);
  62. }
  63.  
  64. }
  65.  
  66. return words;
  67.  
  68. }
  69. static void Main(string[] args)
  70. {
  71. Console.Write("input: ");
  72. Double n = Double.Parse(Console.ReadLine());
  73.  
  74. Console.WriteLine("output: " + "{0}", NumWords(n));
  75.  
  76. Console.ReadLine();
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement