Advertisement
Ilhamrizal_14

Konversi Bilangan [1 - 1 juta]

Oct 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. void satuan (int a)
  9. {
  10. if (a==1)
  11. {
  12. cout<<" Satu ";
  13. }
  14. else if (a==2)
  15. {
  16. cout<<" Dua ";
  17. }
  18. else if (a==3)
  19. {
  20. cout<<" Tiga ";
  21. }
  22. else if (a==4)
  23. {
  24. cout<<" Empat ";
  25. }
  26. else if (a==5)
  27. {
  28. cout<<" Lima ";
  29. }
  30. else if (a==6)
  31. {
  32. cout<<" Enam ";
  33. }
  34. else if (a==7)
  35. {
  36. cout<<" Tujuh ";
  37. }
  38. else if (a==8)
  39. {
  40. cout<<" Delapan ";
  41. }
  42. else if (a==9)
  43. {
  44. cout<<" Sembilan ";
  45. }
  46. else if (a==10)
  47. {
  48. cout<<" Sepuluh ";
  49. }
  50. else if (a==11)
  51. {
  52. cout<<" Sebelas ";
  53. }
  54. }
  55. void terbilang (int b)
  56. {
  57. if (b<=11)
  58. {
  59. satuan(b);
  60. }
  61. else if ((b>11) && (b<20))
  62. {
  63. terbilang(b%10);
  64. cout<<"Belas ";
  65. }
  66. else if ((b>=20)&&(b<100))
  67. {
  68. terbilang(b/10);
  69. cout<<"Puluh";
  70. terbilang(b%10);
  71. }
  72. else if ((b>=100)&&(b<200))
  73. {
  74. cout<<"Seratus";
  75. terbilang(b%100);
  76. }
  77. else if ((b>=200)&&(b<1000))
  78. {
  79. terbilang(b/100);
  80. cout<<"Ratus";
  81. terbilang(b%100);
  82. }
  83. else if ((b>=1000)&&(b<2000))
  84. {
  85. cout<<"Seribu ";
  86. terbilang(b%1000);
  87. }
  88. else if ((b>=2000)&&(b<10000))
  89. {
  90. terbilang(b/1000);
  91. cout<<"Ribu";
  92. terbilang(b%1000);
  93. }
  94. else if ((b>=10000)&&(b<100000))
  95. {
  96. terbilang(b/1000);
  97. cout<<"Ribu";
  98. terbilang(b%1000);
  99. }
  100. else if ((b>=100000)&&(b<1000000))
  101. {
  102. terbilang(b/1000);
  103. cout<<"Ribu";
  104. terbilang(b%1000);
  105. }
  106. else if ((b==1000000))
  107. {
  108. terbilang(b/1000000);
  109. cout<<"Juta";
  110. terbilang(b%1000000);
  111. }
  112. else if ((b>1000000))
  113. {
  114. cout<<"ERROR\n";
  115. cout<<"nilai yang Anda masukan melampaui database, Sorry ya, codingnya udah banyak nih :D";
  116. }
  117. }
  118.  
  119. int main()
  120. {
  121. int nilai;
  122.  
  123. cout<<"============================\n";
  124. cout<<"     KONVERSI BILANGAN \n";
  125. cout<<"============================\n";
  126. cout<<"Masukkan Bilangan Yang Ingin Anda Konversi [1 - 1000000]: ";
  127.  
  128. cin>>nilai;
  129. if (nilai<0){
  130. cout<<"Minus";
  131. terbilang(abs(nilai));
  132. } else {
  133. terbilang(nilai);
  134. }
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement