Advertisement
Ferry_indrawan04

Tugas Nilai Terbilang

Oct 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void satuan (int a)
  6. {
  7.     if (a==1){
  8.         cout << "satu";
  9.     }
  10.     else if (a==2){
  11.         cout << "dua";
  12.     }
  13.     else if (a==3) {
  14.         cout << "tiga";
  15.     }
  16.     else if (a==4){
  17.         cout << "empat";
  18.     }
  19.     else if (a==5){
  20.         cout << "lima";
  21.     }
  22.     else if (a==6){
  23.         cout << "enam";
  24.     }
  25.     else if (a==7){
  26.         cout << "tujuh";
  27.     }
  28.     else if (a==8){
  29.         cout << "delapan";
  30.     }
  31.     else if (a==9){
  32.         cout << "sembilan";
  33.     }
  34.     else if (a==10){
  35.         cout << "sepuluh";
  36.     }
  37.     else if (a==11){
  38.         cout << "sebelas";
  39.     }
  40.  
  41. }
  42. void terbilang (int b)
  43. {
  44.     if (b<=11){
  45.         satuan(b);
  46.     }
  47.     else if ((b>11)&&(b<=19)){
  48.         terbilang (b%10);
  49.         cout << "belas ";
  50.     }
  51.     else if ((b>=20)&&(b<=99)){
  52.         terbilang (b/10);
  53.         cout << "puluh ";
  54.         terbilang (b%10);
  55.     }
  56.     else if ((b>=100)&&(b<=199)){
  57.         cout << "seratus ";
  58.         terbilang (b%100);
  59.     }
  60.     else if ((b>=200)&&(b<=999)){
  61.         terbilang (b/100);
  62.         cout << "ratus ";
  63.         terbilang (b%100);
  64.     }
  65.     else if ((b>=1000)&&(b<=1999)){
  66.         cout << "seribu ";
  67.         terbilang (b%1000);
  68.     }
  69.     else if ((b>=2000)&&(b<=9999)){
  70.         terbilang (b/1000);
  71.         cout << "ribu ";
  72.         terbilang (b%1000);
  73.     }
  74.     else if ((b>=10000)&&(b<=99999)){
  75.     terbilang (b/1000);
  76.     cout << "ribu ";
  77.     terbilang (b%1000);
  78.     }
  79.     else if ((b>=100000)&&(b<=999999)){
  80.         terbilang (b/1000);
  81.         cout << "ribu ";
  82.         terbilang (b%1000);
  83.     }
  84.     else if ((b==1000000)){
  85.         terbilang (b/1000000);
  86.         cout << "juta ";
  87.         terbilang (b%1000000);
  88.     }
  89.     else if((b>10000000)){
  90.         cout << "ERROR!!!" << endl;
  91.         cout << " Nilai Yang Anda Masukkan Terlalu Banyak.";
  92.     }
  93. }
  94. int main()
  95. {
  96. int nilai;
  97. cout << "NAMA : FERRY INDRAWAN" << endl;
  98. cout << "NPM  : 06.2017.1.06837" << endl;
  99. cout << "APLIKASI MENGHITUNG ANGKA KE BILANGAN" <<endl<<endl;
  100. cout << "==================================" <<endl;
  101. cout << "Masukkan Angka: ";
  102. cin >> nilai;
  103.  
  104. if (nilai<0){
  105.     cout <<"minus";
  106.     terbilang (nilai);
  107. }
  108. else{
  109.     terbilang (nilai);
  110. }
  111.  
  112. cout <<endl<< "===================================" << endl;
  113.  
  114.         return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement