16 Oktober 2010 Program ini merupakan latihan praktikum untuk vb.net di suruh membuat program kalkulator sederhana, dengan operator perkalian, pembagian, penambahan dan pengurangan. karena masih sangat newbie banget dalam masalah vb.net, lumyan pusing juga buat bikin program begini, heheheh.
Program seperti gambar di bawah ini:
kalau ingin kembali menghitung ketik y, kemudian enter.
Untuk coding ada 2 cara, cara pertama
Module Module1
Sub Main()
'write => tulisannya disamping klo writeline tulisannya dibawah
A: Console.Clear()
Console.WriteLine("KALKULATOR MINI")
Console.WriteLine("silahkan mencoba")
Console.WriteLine("----------------------------------------")
Console.Write("Bilangan 1 : ")
Dim xAngka1 As double
xAngka1 = Console.ReadLine()
Console.Write("Operasi (x,/,+,-) : ")
Dim xOperasi As String
xOperasi = Console.ReadLine()
Console.Write("Bilangan 2 : ")
Dim xAngka2 As Double
xAngka2 = Console.ReadLine()
Select Case UCase(xOperasi)
Case "X"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 * xAngka2)
Case "/"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 / xAngka2)
Case "+"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 + xAngka2)
Case "-"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 - xAngka2)
Case Else
Console.WriteLine()
Console.WriteLine("Anda salah memasukkan operasi")
End Select
Console.WriteLine()
Console.WriteLine("----------------------------------------")
Console.Write("Ulangi lagi? (Y/T): ")
Dim xUlang As String
xUlang = Console.ReadLine()
Select Case UCase(xUlang)
Case "Y"
GoTo A
Case Else
Console.Write("Terima Kasih")
Console.ReadLine()
End Select
End Sub
End Module
Sub Main()
'write => tulisannya disamping klo writeline tulisannya dibawah
A: Console.Clear()
Console.WriteLine("KALKULATOR MINI")
Console.WriteLine("silahkan mencoba")
Console.WriteLine("----------------------------------------")
Console.Write("Bilangan 1 : ")
Dim xAngka1 As double
xAngka1 = Console.ReadLine()
Console.Write("Operasi (x,/,+,-) : ")
Dim xOperasi As String
xOperasi = Console.ReadLine()
Console.Write("Bilangan 2 : ")
Dim xAngka2 As Double
xAngka2 = Console.ReadLine()
Select Case UCase(xOperasi)
Case "X"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 * xAngka2)
Case "/"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 / xAngka2)
Case "+"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 + xAngka2)
Case "-"
Console.WriteLine()
Console.WriteLine("--------------------------")
Console.WriteLine()
Console.Write("Hasil : ")
Console.WriteLine(xAngka1 - xAngka2)
Case Else
Console.WriteLine()
Console.WriteLine("Anda salah memasukkan operasi")
End Select
Console.WriteLine()
Console.WriteLine("----------------------------------------")
Console.Write("Ulangi lagi? (Y/T): ")
Dim xUlang As String
xUlang = Console.ReadLine()
Select Case UCase(xUlang)
Case "Y"
GoTo A
Case Else
Console.Write("Terima Kasih")
Console.ReadLine()
End Select
End Sub
End Module
Cara kedua
Module Module1
Sub Main()
Console.Clear()
Console.WriteLine("Program Kalkulator Sederhana")
Console.WriteLine("--------------------------------------")
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Char
Console.Write("Bilangan 1 : ")
a = Console.ReadLine()
Console.WriteLine()
Console.Write("Operasi (+/-/*//): ")
d = Console.ReadLine
Console.WriteLine()
Console.Write("Bilangan 2 : ")
b = Console.ReadLine
Console.WriteLine()
Select Case UCase(d)
Case "+"
c = a + b
Console.WriteLine("Hasil: " & c & " ")
Case "-"
c = a - b
Console.WriteLine("Hasil: " & c & " ")
Case "*"
c = a * b
Console.WriteLine("Hasil: " & c & " ")
Case "/"
c = a / b
Console.WriteLine("Hasil: " & c & " ")
Case Else
Console.WriteLine("Anda Salah Memasukkan Tanda")
End Select
Console.WriteLine("-----------------------------------")
Repeater()
End Sub
Private Sub Repeater()
Dim pilih As Char
Console.Write("Mau Ulang(y/n)?")
pilih = Console.ReadLine()
If pilih = "y" Then
Main()
ElseIf pilih = "Y" Then
Main()
Else
Console.Write("Terima Kasih")
Console.ReadLine()
End If
End Sub
End Module
Sub Main()
Console.Clear()
Console.WriteLine("Program Kalkulator Sederhana")
Console.WriteLine("--------------------------------------")
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Char
Console.Write("Bilangan 1 : ")
a = Console.ReadLine()
Console.WriteLine()
Console.Write("Operasi (+/-/*//): ")
d = Console.ReadLine
Console.WriteLine()
Console.Write("Bilangan 2 : ")
b = Console.ReadLine
Console.WriteLine()
Select Case UCase(d)
Case "+"
c = a + b
Console.WriteLine("Hasil: " & c & " ")
Case "-"
c = a - b
Console.WriteLine("Hasil: " & c & " ")
Case "*"
c = a * b
Console.WriteLine("Hasil: " & c & " ")
Case "/"
c = a / b
Console.WriteLine("Hasil: " & c & " ")
Case Else
Console.WriteLine("Anda Salah Memasukkan Tanda")
End Select
Console.WriteLine("-----------------------------------")
Repeater()
End Sub
Private Sub Repeater()
Dim pilih As Char
Console.Write("Mau Ulang(y/n)?")
pilih = Console.ReadLine()
If pilih = "y" Then
Main()
ElseIf pilih = "Y" Then
Main()
Else
Console.Write("Terima Kasih")
Console.ReadLine()
End If
End Sub
End Module
Selamat mencoba :)
by : http://allaboutalgoritma.blogspot.com
0 comments:
Posting Komentar