Saturday, June 16, 2012

Simple Calculation in vb.net

I saw someone posting an example of simple calculation in C++ in some forum the other day. It is basically counting the amount of money needed based on holiday package chosen and number of person going.
I was bored and i did my own version using vb.net.



Module Module1

    Dim no1, no2, total As Integer
    'Dim total As Double = 0
    Dim pakej As String
    Dim orang As String

    Sub Main()

        Do While (True)

            Console.WriteLine("-----------------------")
            Console.WriteLine("Promosi Pakej Percutian")
            Console.WriteLine("-----------------------")
            Console.WriteLine("")

            Console.WriteLine("--------Pakej----------")
            Console.WriteLine("")
            Console.WriteLine("1. P.Langkawi   = Rm300")
            Console.WriteLine("2. P.Tioman     = Rm400")
            Console.WriteLine("3. P.Perhentian = Rm500")
            Console.WriteLine("4. P.Redang     = Rm600")
            Console.WriteLine("-----------------------")
            Console.WriteLine("")

            Console.WriteLine("Sila pilih pakej pilihan anda.")
            Console.WriteLine("")
            Dim pakej = Console.ReadLine()

            Console.WriteLine("")
            Console.WriteLine("Pakej pilihan = " & pakej)
            Console.WriteLine("")
            Console.WriteLine("Sila masukkan bilangan orang.")
            Console.WriteLine("")
            Dim orang = Console.ReadLine()
            Console.WriteLine("")
            Console.WriteLine("Bilangan orang = " & orang)
            Console.WriteLine("")

            no1 = pakej
            no2 = orang

            If pakej = 1 Then
                no1 = 300
            ElseIf pakej = 2 Then
                no1 = 400
            ElseIf pakej = 3 Then
                no1 = 500
            ElseIf pakej = 4 Then
                no1 = 600
            Else
                Console.WriteLine("Invalid package")
                Stop
            End If

            total = (no1 * no2)
            Console.WriteLine("Jumlah bayaran = Rm " & total)
            Console.WriteLine("")
            Console.WriteLine("Press any button to continue.")
            Console.ReadLine()

        Loop

    End Sub

End Module

No comments:

Post a Comment