Advertisement
Hilmyhim

Tugas Konversi Bilangan

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