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

การคำนวณหาส่วนลด

ขาย vcd แผ่นละ 456 บาท ถ้าซื้อเกิน 5 ชิ้นจะได้รับส่วนลด 5%  และถ้าเป็นสมาชิกด้วยจะได้รับส่วนลดอีก 5%
  1. Module VCD
  2.     Dim qty, vcd As Integer
  3.     Dim member As String
  4.     Dim discount, sale, total As Decimal

  5.     Sub Main()
  6.         Console.WriteLine("How much VCD(s)?")
  7.         qty = Console.ReadLine()
  8.         Console.WriteLine("Member (y/n)?")
  9.         member = Console.ReadLine()
  10.         If qty > 5 AndAlso member = "y" Then
  11.             vcd = 456
  12.             sale = (vcd * 10) / 100
  13.             discount = vcd - sale
  14.             total = discount * qty
  15.             Console.WriteLine("Discount = " & discount & " bath")
  16.             Console.WriteLine("Total = " & total & " bath")
  17.         ElseIf qty > 5 OrElse member = "y" Then
  18.             vcd = 456
  19.             sale = (vcd * 5) / 100
  20.             discount = vcd - sale
  21.             total = discount * qty
  22.             Console.WriteLine("Discount = " & discount & " bath")
  23.             Console.WriteLine("Total = " & total & " bath")
  24.         Else
  25.             vcd = 456
  26.             discount = vcd
  27.             total = discount * qty
  28.             Console.WriteLine("Discount = " & discount & " bath")
  29.             Console.WriteLine("Total = " & total & " bath")
  30.         End If
  31.     End Sub

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


ผันรันเมื่อซื้อเกิน 5 ชิ้นและเป็นสมาชิก
2009-12-22_223638.jpg
2009-12-22 22:40

ผันรันเมื่อซื้อเกิน 5 ชิ้นแต่ไม่ได้เป็นสมาชิก
2009-12-22_223707.jpg
2009-12-22 22:40

ผันรันเมื่อซื้อน้อยกว่า 5 ชิ้นแต่เป็นสมาชิก
2009-12-22_223733.jpg
2009-12-22 22:40

ผันรันเมื่อซื้อน้อยกว่า 5 ชิ้นและไม่ได้เป็นสมาชิก
2009-12-22_223745.jpg
2009-12-22 22:40




อยากถามรุ่นพี่ว่าถ้าเขียน Code ด้านล่างนี้ พอจะใช้ได้ป่ะครับ
Module Module1
    Dim total, discount As Decimal
    Dim vcd As Integer
    Dim member As String
    Sub Main()
        Console.WriteLine("How many vcd?(s): ")
        vcd = Console.ReadLine
        Console.WriteLine("Are you member?(y/n): ")
        member = Console.ReadLine
        If vcd > 5 AndAlso member = ("y") Then
            discount = vcd * 456 * 10 / 100
            total = vcd * 456 - discount
        ElseIf vcd > 5 AndAlso member = ("n") Then
            discount = vcd * 456 * 5 / 100
            total = vcd * 456 - discount
        ElseIf vcd <= 5 AndAlso member = ("y") Then
            discount = vcd * 456 * 5 / 100
            total = vcd * 456 - discount
        Else
            discount = vcd * 456 * 0 / 100
            total = vcd * 456 - discount
        End If
        Console.WriteLine("discount = " & discount & "baht")
        Console.WriteLine("total = " & total & "baht")
    End Sub
End Module

TOP

แก้ไขล่าสุด noom เมื่อ 2009-12-25 15:36
อยากถามรุ่นพี่ว่าถ้าเขียน Code ด้านล่างนี้ พอจะใช้ได้ ...
ต้นฉบับโพสโดย onenonggap เมื่อ 2009-12-25 09:13


ถ้าจะให้ใช้ได้ก็ตามนี้เลยครับ ตัวสีแดงคือสิ่งที่แก้
*เราหาส่วนลดจากราคาแผ่นนะครับไม่ได้หาจากราคารวม
  1. Dim total, discount, sale As Decimal
  2.     Dim vcd As Integer
  3.     Dim member As String
  4.     Sub Main()
  5.         Console.WriteLine("How many vcd?(s): ")
  6.         vcd = Console.ReadLine
  7.         Console.WriteLine("Are you member?(y/n): ")
  8.         member = Console.ReadLine
  9.         If vcd > 5 AndAlso member = ("y") Then
  10.             sale = 456 * 10 / 100
  11.             discount = 456 - sale
  12.             total = vcd * discount
  13.         ElseIf vcd > 5 AndAlso member = ("n") Then
  14.             sale = 456 * 5 / 100
  15.             discount = 456 - sale
  16.             total = vcd * discount
  17.         ElseIf vcd < 5 AndAlso member = ("y") Then
  18.             sale = 456 * 5 / 100
  19.             discount = 456 - sale
  20.             total = vcd * discount
  21.         Else
  22.             discount = 456
  23.             total = vcd * discount
  24.         End If
  25.         Console.WriteLine("discount = " & discount & "baht")
  26.         Console.WriteLine("total = " & total & "baht")
  27.     End Sub
คัดลอกไปที่คลิปบอร์ด




TOP

ขอบคุณมากนะครับ ที่ให้คำแนะนำ

TOP

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