Fungsi Terbilang Console Application

alfa6661
- December 20, 2011
0 (0 votes)
Rate :
Membuat fungsi terbilang pada Visual Basic .Net

Fungsi terbilang merupakan fungsi untuk mencetak kalimat yang mendeskripsikan suatu bilangan. Sering sekali dalam pembuatan sebuah program, terutama program berhaluan bisnis, program harus melafalkan nilai nominal uang dalam bentuk kata - kata, salah satu contohnya adalah kwitansi.

Syntax

Module Module1
 
    Public Function Terbilang(ByVal x As Integer) As String
 
        Dim bilangan As String() = {"", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"}
 
        Dim temp As String = ""
 
        If x < 12 Then
            temp = bilangan(x)
        ElseIf x < 20 Then
            temp = Terbilang(x - 10) + " belas "
        ElseIf x < 100 Then
            temp = Terbilang(x / 10) + " puluh " + Terbilang(x Mod 10)
        ElseIf x < 200 Then
            temp = " seratus" + Terbilang(x - 100)
        ElseIf x < 1000 Then
            temp = Terbilang(x / 100) + " ratus " + Terbilang(x Mod 100)
        ElseIf x < 2000 Then
            temp = " seribu " + Terbilang(x - 1000)
        ElseIf x < 1000000 Then
            temp = Terbilang(x / 1000) + " ribu " + Terbilang(x Mod 1000)
        ElseIf x < 1000000000 Then
            temp = Terbilang(x / 1000000) + " juta " + Terbilang(x Mod 1000000)
        End If
 
        Return temp
 
    End Function
 
    Sub main()
        Dim bilang As String
        Dim nilai As Long
 
        Console.Write("Masukan bilangan : ")
        nilai = Console.ReadLine
        bilang = Terbilang(nilai)
        Console.Write(bilang)
        Console.ReadKey()
    End Sub
 
End Module

Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter

– Eric S. Raymond

Have a better explanation?

If you have comments about this post. Please write your comments below

No comments associated with this article