|
  
- โพสต์แล้ว
- 136
- เครดิต
- 64
- จิตพิศัย
- 64 0
- Money
- 49 10
- เพศ
- ชาย
- ลงทะเบียนเมื่อ
- 2009-12-20
|
ตัวอย่างโปรแกรมคำนวณหาส่วนลด VCD โดยการสร้างฟังก์ชั่น
- Module VCD
- Function vcd(ByVal qty As Integer, ByVal member As String) As Decimal
- Dim total As Decimal = 0
- Dim discount As Decimal = 0
- Dim dis As Decimal
- If qty >= 5 AndAlso member = "y" Then
- dis = 456 * 10 / 100
- discount = 456 - dis
- total = qty * discount
- ElseIf qty < 5 AndAlso member = "y" Then
- dis = 456 * 5 / 100
- discount = 456 - dis
- total = qty * discount
- ElseIf qty > 5 AndAlso member = "n" Then
- dis = 456 * 5 / 100
- discount = 456 - dis
- total = qty * discount
- Else
- discount = 456
- total = qty * discount
- End If
- Console.WriteLine("Discount = " & discount & " baht" & vbCrLf & "Total = " & total & " baht")
- End Function
- Sub Main()
- Dim qty As Integer
- Dim member As String
- Console.WriteLine("How many VCD(s)?")
- qty = Console.ReadLine()
- Console.WriteLine("Are you Member? (y/n)")
- member = Console.ReadLine()
- vcd(qty, member)
- End Sub
- End Module
คัดลอกไปที่คลิปบอร์ด
ตัวอย่าง ผลรัน
|
|