Advertisement
khisby

menghitung suhu,konversi angka ke nama angka,diamon

Nov 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <math.h>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8. void satuan (int a)
  9. {
  10.     if (a==1) {
  11.         cout<<" Satu ";
  12.     }else if (a==2) {
  13.         cout<<" Dua ";
  14.     }else if (a==3) {
  15.         cout<<" Tiga ";
  16.     }else if (a==4) {
  17.         cout<<" Empat ";
  18.     }else if (a==5) {
  19.         cout<<" Lima ";
  20.     }else if (a==6) {
  21.         cout<<" Enam ";
  22.     }else if (a==7) {
  23.         cout<<" Tujuh ";
  24.     }else if (a==8) {
  25.         cout<<" Delapan ";
  26.     }else if (a==9) {
  27.         cout<<" Sembilan ";
  28.     }else if (a==10) {
  29.         cout<<" Sepuluh ";
  30.     }else if (a==11) {
  31.         cout<<" Sebelas ";
  32.     }
  33. }
  34. void terbilang (int b){
  35.     if (b<=11) {
  36.         satuan(b);
  37.     }else if((b>11) && (b<=19)){
  38.         terbilang(b%10);
  39.         cout<<"Belas ";
  40.     }else if ((b>=20)&&(b<=99)) {
  41.         terbilang(b/10);
  42.         cout<<"Puluh";
  43.         terbilang(b%10);
  44.     }else if ((b>=100)&&(b<=199)) {
  45.         cout<<"Seratus";
  46.         terbilang(b%100);
  47.     }else if ((b>=200)&&(b<=999)) {
  48.         terbilang(b/100);
  49.         cout<<"Ratus";
  50.         terbilang(b%100);
  51.     }else if ((b>=1000)&&(b<=1999)) {
  52.         cout<<"Seribu";
  53.         terbilang(b%1000);
  54.     }else if ((b>=2000)&&(b<=9999)) {
  55.         terbilang(b/1000);
  56.         cout<<"Ribu";
  57.         terbilang(b%1000);
  58.     }else if ((b>=10000)&&(b<=99999)) {
  59.         terbilang(b/1000);
  60.         cout<<"Ribu";
  61.         terbilang(b%1000);
  62.     }else if ((b>=100000)&&(b<=999999)) {
  63.         terbilang(b/1000);
  64.         cout<<"Ribu";
  65.         terbilang(b%1000);
  66.     }else if ((b==1000000)) {
  67.         terbilang(b/1000000);
  68.         cout<<"Juta";
  69.         terbilang(b%1000000);
  70.     }else if ((b>1000000)){
  71.         cout<<"ERROR\n";
  72.         cout<<"nilai yang Anda masukan melampaui database aplikasi";
  73.     }
  74. }
  75. int main()
  76. {
  77.     int pilih, pilih1, c, r, k, pola,i,n,j   ;
  78.     double hasil;
  79.     do{
  80.     cout << ""<< endl ;
  81.     cout<<"Menu"<<endl;
  82.     cout<<"1. Menghitung suhu"<<endl;
  83.     cout<<"2. Konversi"<<endl;
  84.     cout<<"3. Pola Diamond"<<endl;
  85.     cout<<"4. Exit"<<endl;
  86.     cout<<"Masukkan pilihan anda: ";
  87.     cin>>pilih;
  88.     switch(pilih){
  89.  
  90.         case 1:
  91.             cout << ""<< endl ;
  92.             cout<<"Menu Menghitung suhu"<<endl;
  93.             cout<<"1. fahrenheit ke celcius"<<endl;
  94.             cout<<"2. fahrenheit ke reamur"<<endl;
  95.             cout<<"3. fahrenheit ke kelvin"<<endl;
  96.             cout<<"Masukkan pilihan anda: ";
  97.             cin>>pilih1;
  98.             switch(pilih1){
  99.                 case 1:
  100.                     cout<<"masukkan suhu fahrenheit "; cin>>c;
  101.                     hasil = 0.55*(c-32);
  102.                     cout << "Hasilnya adalah : " << hasil <<endl ;
  103.                     break;
  104.                 case 2:
  105.                     cout<<"masukkan suhu fahrenheit "; cin>>r;
  106.                     hasil = 0.44*(r-32);
  107.                     cout << "Hasilnya adalah : " << hasil <<endl ;
  108.                     break;
  109.                 case 3:
  110.                     cout<<"masukkan suhu fahrenheit ";cin>>k;
  111.                     hasil = 0.55*(k-32)+273.15;
  112.                     cout << "Hasilnya adalah : " << hasil <<endl ;
  113.                     break;
  114.                 }
  115.             break;
  116.  
  117.            case 2:{
  118.             cout << ""<< endl ;
  119.             int nilai;
  120.             string angka;
  121.             cout<<"Masukkan Bilangan Anda: ";
  122.             cin>>nilai;
  123.                 int i=1;
  124.                 while(i<=nilai){
  125.                     cout << i;
  126.                     terbilang(i);
  127.                     cout << endl;
  128.                     i++;
  129.                 }
  130.             cout<<"\n============================\n";
  131.            }break;
  132.  
  133.             case 3:
  134.             cout << ""<< endl ;
  135.             cout<<"Pola diamond"<<endl;
  136.             cout<<"masukkan angka "<<endl; cin>>n;
  137.  
  138.             for (i=1 ; i<=n; i++)
  139.             {
  140.             for (j=0; j < (n-i); j++)
  141.                 cout <<" ";
  142.             for (j=1; j<=i;j++)
  143.                 cout<<"* ";
  144.              cout<<"\n";
  145.             }
  146.             for (i=2; i<=n; i++)
  147.             {
  148.             for (j = n-i;j<=n-2; j++)
  149.                 cout<<" ";
  150.             {
  151.                 for (j=n-i;j>=0;j--)
  152.                     cout<<"* ";
  153.             }
  154.             cout<<"\n";
  155.             }
  156.  
  157.  
  158.  
  159.     }
  160.     }while(pilih!=4);
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement