Advertisement
kenettedagal

Untitled

Jul 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int num;
  10. string ones,tens,hundreds,thousands,tenthousands;
  11. cout << "Enter a number from 0 to 99999"<< endl ;
  12. cin >> num;
  13.  
  14. int numleng = to_string(num).length(); // determine how many digits was inputted
  15.  
  16. if(num >99999 || num < 0)
  17. {
  18. cout<< "Out of range!" << endl;
  19. }
  20.  
  21. if (numleng == 1)
  22. {
  23. if(num == 0){ ones = "zero";}
  24. if(num == 1){ ones = "one";}
  25. if(num == 2){ ones = "two";}
  26. if(num == 3){ ones = "three";}
  27. if(num == 4){ ones = "four";}
  28. if(num == 5){ ones = "five";}
  29. if(num == 6){ ones = "six";}
  30. if(num == 7){ ones = "seven";}
  31. if(num == 8){ ones = "eight";}
  32. if(num == 9){ ones = "nine";}
  33.  
  34. cout << ones ;
  35. }
  36.  
  37. else if (numleng == 2)
  38. {
  39. if (num <= 19 && num >= 10)
  40. {
  41. if(num == 10){ tens = "ten";}
  42. if(num == 11){ tens = "eleven";}
  43. if(num == 12){ tens = "twelve";}
  44. if(num == 13){ tens = "thirteen";}
  45. if(num == 14){ tens = "fourteen";}
  46. if(num == 15){ tens = "fifteen";}
  47. if(num == 16){ tens = "sixteen";}
  48. if(num == 17){ tens = "seventeen";}
  49. if(num == 18){ tens = "eighteen";}
  50. if(num == 19){ tens = "nineteen";}
  51.  
  52. cout<<tens;
  53. }
  54. else if (num <= 99 && num >=20)
  55. {
  56.  
  57. if(num == 20){ tens = "twenty";}
  58. if(num == 30){ tens = "thirty";}
  59. if(num == 40){ tens = "forty";}
  60. if(num == 50){ tens = "fifty";}
  61. if(num == 60){ tens = "sixty";}
  62. if(num == 70){ tens = "seventy";}
  63. if(num == 80){ tens = "eighty";}
  64. if(num == 90){ tens = "ninety";}
  65.  
  66. cout<< tens;
  67. }
  68. }
  69. else if (numleng == 3)
  70. {
  71. int firstnum = num % 10;
  72. int secnum = (num / 10) % 10;
  73. int thirdnum = ((num / 10) / 10) % 10;
  74. int gethund = (num/100)*100;
  75. int exception = num - gethund;
  76.  
  77. if(exception<=19 && exception >= 10 )
  78. {
  79. if(thirdnum == 1){ hundreds = "one hundred ";}
  80. if(thirdnum == 2){ hundreds = "two hundred ";}
  81. if(thirdnum == 3){ hundreds = "three hundred ";}
  82. if(thirdnum == 4){ hundreds = "four hundred ";}
  83. if(thirdnum == 5){ hundreds = "five hundred ";}
  84. if(thirdnum == 6){ hundreds = "six hundred ";}
  85. if(thirdnum == 7){ hundreds = "seven hundred ";}
  86. if(thirdnum == 8){ hundreds = "eight hundred ";}
  87. if(thirdnum == 9){ hundreds = "nine hundred ";}
  88.  
  89. if(exception == 10){ tens = "ten";}
  90. if(exception == 11){ tens = "eleven";}
  91. if(exception == 12){ tens = "twelve";}
  92. if(exception == 13){ tens = "thirteen";}
  93. if(exception == 14){ tens = "fourteen";}
  94. if(exception == 15){ tens = "fifteen";}
  95. if(exception == 16){ tens = "sixteen";}
  96. if(exception == 17){ tens = "seventeen";}
  97. if(exception == 18){ tens = "eighteen";}
  98. if(exception == 19){ tens = "nineteen";}
  99.  
  100. cout << hundreds << tens ;
  101. }
  102. else{
  103. if(thirdnum == 1){ hundreds = "one hundred ";}
  104. if(thirdnum == 2){ hundreds = "two hundred ";}
  105. if(thirdnum == 3){ hundreds = "three hundred ";}
  106. if(thirdnum == 4){ hundreds = "four hundred ";}
  107. if(thirdnum == 5){ hundreds = "five hundred ";}
  108. if(thirdnum == 6){ hundreds = "six hundred ";}
  109. if(thirdnum == 7){ hundreds = "seven hundred ";}
  110. if(thirdnum == 8){ hundreds = "eight hundred ";}
  111. if(thirdnum == 9){ hundreds = "nine hundred ";}
  112.  
  113. if(secnum == 2){ tens = "twenty";}
  114. if(secnum == 3){ tens = "thirty";}
  115. if(secnum == 4){ tens = "forty";}
  116. if(secnum == 5){ tens = "fifty";}
  117. if(secnum == 6){ tens = "sixty";}
  118. if(secnum == 7){ tens = "seventy";}
  119. if(secnum == 8){ tens = "eighty";}
  120. if(secnum == 9){ tens = "ninety";}
  121.  
  122. if(firstnum == 0){ ones = "";}
  123. if(firstnum == 1){ ones = "one";}
  124. if(firstnum == 2){ ones = "two";}
  125. if(firstnum == 3){ ones = "three";}
  126. if(firstnum == 4){ ones = "four";}
  127. if(firstnum == 5){ ones = "five";}
  128. if(firstnum == 6){ ones = "six";}
  129. if(firstnum == 7){ ones = "seven";}
  130. if(firstnum == 8){ ones = "eight";}
  131. if(firstnum == 9){ ones = "nine";}
  132.  
  133. cout << hundreds << tens << " " << ones ;
  134. }
  135.  
  136.  
  137. }
  138.  
  139.  
  140.  
  141.  
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement