กลับไปรายการกระดาน โพสต์

ตัวอย่างโปรแกรมคำนวณหาส่วนลด VCD โดยการสร้างฟังก์ชั่น

  1. Module VCD
  2.     Function vcd(ByVal qty As Integer, ByVal member As String) As Decimal
  3.         Dim total As Decimal = 0
  4.         Dim discount As Decimal = 0
  5.         Dim dis As Decimal
  6.         If qty >= 5 AndAlso member = "y" Then
  7.             dis = 456 * 10 / 100
  8.             discount = 456 - dis
  9.             total = qty * discount
  10.         ElseIf qty < 5 AndAlso member = "y" Then
  11.             dis = 456 * 5 / 100
  12.             discount = 456 - dis
  13.             total = qty * discount
  14.         ElseIf qty > 5 AndAlso member = "n" Then
  15.             dis = 456 * 5 / 100
  16.             discount = 456 - dis
  17.             total = qty * discount
  18.         Else
  19.             discount = 456
  20.             total = qty * discount
  21.         End If
  22.         Console.WriteLine("Discount = " & discount & " baht" & vbCrLf & "Total = " & total & " baht")
  23.     End Function
  24.     Sub Main()
  25.         Dim qty As Integer
  26.         Dim member As String
  27.         Console.WriteLine("How many VCD(s)?")
  28.         qty = Console.ReadLine()
  29.         Console.WriteLine("Are you Member? (y/n)")
  30.         member = Console.ReadLine()
  31.         vcd(qty, member)
  32.     End Sub

  33. End Module
คัดลอกไปที่คลิปบอร์ด


ตัวอย่าง ผลรัน

2010-01-19_200327.jpg
2010-1-19 20:07


2010-01-19_200343.jpg
2010-1-19 20:07




กลับไปรายการกระดาน