Di kesempatan yang ada ini, saya akan
bagaimana membuat program yang ‘mengkonversi’ angka menjadi huruf terbilang.
Jika saya pikir-pikir, konsep dasar mengubah
angka ke huruf cukup sulit. Karena angka sangat flexible sehingga dapat
bernilai berapa saja, dan harus memikirkan bagaimana cara untuk membuat program
‘pengkonversi’ seperti itu. Konsep paling ‘make sense’ yang bisa saya
implementasikan setelah berpikir-pikir adalah dengan prosedur dan kondisi
bersarang (nested if). Jika saya jelaskan semuanya di text ini, akan terlalu
banyak. Jadi pada dasarnya, inputan angka tertentu akan menghasilkan output
tertentu juga (terbilang) dengan prosedur dalam kondisi bersarang.
Nim = A11.2018.10849
Kelompok = A11.4101
// Judul
PENGUBAHAN ANGKA KE TERBILANG
PENGUBAHAN ANGKA KE TERBILANG
/ Kamus
terbilang ß void
jumUang ß integer
terbilang ß void
jumUang ß integer
// Deskripsi
input (jumUang)
terbilang(jumUang)
input (jumUang)
terbilang(jumUang)
void terbilang (x ß integer)
{
if(x=1)
{
output “Satu “
}
else if(x=2)
{
output “Dua “
}
else if(x=3)
{
output “Tiga “
}
else if(x=4)
{
output “Empat “
}
else if(x=5)
{
output “Lima “
}
else if(x=6)
{
output “Enam “
}
else if(x=7)
{
output “Tujuh “
}
else if(x=8)
{
output “Delapan “
}
else if(x=9)
{
output “Sembilan “
}
else if(x=10)
{
output “Sepuluh “
}
else if(x=11)
{
output “Sebelas “
}
else if(x>=12 and x<=19)
{
terbilang(x mod 10)
output “Belas “
}
else if(x>=20 and x<=99)
{
terbilang(x div 10)
output “Puluh “
terbilang(x mod 10)
}
else if(x>=100 and x<=199)
{
output “Seratus “
terbilang(x-100)
}
else if(x>=200 and x<=999)
{
terbilang(x div 100)
output “Ratus “
terbilang(x mod 100)
}
else if(x>=1000 and x<=1999)
{
output “Seribu “
terbilang(x-1000)
}
else if(x>=2000 and x<=999999)
{
terbilang(x div 1000)
output “Ribu “
terbilang(x mod 1000)
}
else if(x>=1000000 and x<=999999999)
{
terbilang(x div 1000000)
output “Juta “
terbilang(x mod 1000000)
}
else
{
output(“Terlalu banyak “)
}
output (“Rupiah”)
}
{
if(x=1)
{
output “Satu “
}
else if(x=2)
{
output “Dua “
}
else if(x=3)
{
output “Tiga “
}
else if(x=4)
{
output “Empat “
}
else if(x=5)
{
output “Lima “
}
else if(x=6)
{
output “Enam “
}
else if(x=7)
{
output “Tujuh “
}
else if(x=8)
{
output “Delapan “
}
else if(x=9)
{
output “Sembilan “
}
else if(x=10)
{
output “Sepuluh “
}
else if(x=11)
{
output “Sebelas “
}
else if(x>=12 and x<=19)
{
terbilang(x mod 10)
output “Belas “
}
else if(x>=20 and x<=99)
{
terbilang(x div 10)
output “Puluh “
terbilang(x mod 10)
}
else if(x>=100 and x<=199)
{
output “Seratus “
terbilang(x-100)
}
else if(x>=200 and x<=999)
{
terbilang(x div 100)
output “Ratus “
terbilang(x mod 100)
}
else if(x>=1000 and x<=1999)
{
output “Seribu “
terbilang(x-1000)
}
else if(x>=2000 and x<=999999)
{
terbilang(x div 1000)
output “Ribu “
terbilang(x mod 1000)
}
else if(x>=1000000 and x<=999999999)
{
terbilang(x div 1000000)
output “Juta “
terbilang(x mod 1000000)
}
else
{
output(“Terlalu banyak “)
}
output (“Rupiah”)
}
Tidak ada komentar:
Posting Komentar