Pages

Senin, 14 Maret 2011

Tugas Individu mengenai program konversi uang dari angka ke huruf

Konversi Uang ke Bilangan

#include <cstdlib>
#include <iostream>

using namespace std;

void ribu(int ribuan){
     switch(ribuan){
               case 1 : cout<<"seribu ";break;
               case 2 : cout<<"dua ribu ";break;
               case 3 : cout<<"tiga ribu ";break;
               case 4 : cout<<"empat ribu ";break;
               case 5 : cout<<"lima ribu ";break;
               case 6 : cout<<"enam ribu ";break;
               case 7 : cout<<"tujuh ribu ";break;
               case 8 : cout<<"delapan ribu ";break;
               case 9 : cout<<"sembilan ribu ";break;
               }
     }
    
void ratus(int ratusan){
     switch(ratusan){
               case 1 : cout<<"seratus ";break;
               case 2 : cout<<"dua ratus ";break;
               case 3 : cout<<"tiga ratus ";break;
               case 4 : cout<<"empat ratus ";break;
               case 5 : cout<<"lima ratus ";break;
               case 6 : cout<<"enam ratus ";break;
               case 7 : cout<<"tujuh ratus ";break;
               case 8 : cout<<"delapan ratus ";break;
               case 9 : cout<<"sembilan ratus ";break;
               }    
     }
    
void puluh(int puluhan){
     switch(puluhan){
               case 1 : cout<<"sepuluh ";break;
               case 2 : cout<<"dua puluh ";break;
               case 3 : cout<<"tiga puluh ";break;
               case 4 : cout<<"empat puluh ";break;
               case 5 : cout<<"lima puluh ";break;
               case 6 : cout<<"enam puluh ";break;
               case 7 : cout<<"tujuh puluh ";break;
               case 8 : cout<<"delapan puluh ";break;
               case 9 : cout<<"sembilan puluh ";break;
               }    
     }
 
void satu(int satuan){
     switch(satuan){
               case 1 : cout<<"satu ";break;
               case 2 : cout<<"dua ";break;
               case 3 : cout<<"tiga ";break;
               case 4 : cout<<"empat ";break;
               case 5 : cout<<"lima ";break;
               case 6 : cout<<"enam ";break;
               case 7 : cout<<"tujuh ";break;
               case 8 : cout<<"delapan ";break;
               case 9 : cout<<"sembilan ";break;
               }    
     }

void belas(int satuan){
     switch(satuan){
               case 0 : cout<<"sepuluh ";break;
               case 1 : cout<<"sebelas ";break;
               case 2 : cout<<"dua belas ";break;
               case 3 : cout<<"tiga belas ";break;
               case 4 : cout<<"empat belas ";break;
               case 5 : cout<<"lima belas ";break;
               case 6 : cout<<"enam belas ";break;
               case 7 : cout<<"tujuh belas ";break;
               case 8 : cout<<"delapan belas ";break;
               case 9 : cout<<"sembilan belas ";break;
               }
     }
       
int main(int argc, char *argv[])
{
    int uang;
    int ribuan, ratusan, puluhan, satuan;
    int sisa_uang;
   
    cout<<"masukkan uang max 9999 : ";
    cin>> uang;
   
    ribuan = uang / 1000;
    sisa_uang = uang % 1000;
    ratusan = sisa_uang / 100;
    sisa_uang = sisa_uang % 100;
    puluhan = sisa_uang / 10;
    sisa_uang = sisa_uang % 10;
    satuan = sisa_uang;
   
    cout<<"uang dalam huruf : ";
    ribu(ribuan);
    ratus(ratusan);
    if(puluhan != 1){
               puluh(puluhan);
               satu(satuan);
               }
    else{
         belas(satuan);
         }
    cout<<"rupiah";
   
    cout<<endl<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

0 komentar:

Posting Komentar