Asp classic 如何为每购买第五件商品应用折扣价格?

Asp classic 如何为每购买第五件商品应用折扣价格?,asp-classic,Asp Classic,我的代码是用经典ASP编写的,但只要你能用任何语言(PHP、JavaScript、Java)给我一些提示或算法,我就能用经典ASP编写出来 我已设法按价格降序排列了我的记录集。更昂贵的物品是第一位的。目前,我循环遍历记录集,并将每个项放入多维数组中 Do While NOT RS.EOF arrBought(itemcount, 0) = RS("ItemID") arrBought(itemcount, 1) = RS("Price") arrBought(itemco

我的代码是用经典ASP编写的,但只要你能用任何语言(PHP、JavaScript、Java)给我一些提示或算法,我就能用经典ASP编写出来

我已设法按价格降序排列了我的记录集。更昂贵的物品是第一位的。目前,我循环遍历记录集,并将每个项放入多维数组中

Do While NOT RS.EOF
    arrBought(itemcount, 0) = RS("ItemID")
    arrBought(itemcount, 1) = RS("Price")
    arrBought(itemcount, 2) = RS("QuantityBought")

    RS.MoveNext
    itemcount = itemcount + 1
Loop
但是,我如何修改上述循环,为按数量购买的每5件商品分配20%的折扣

比如说,客户购买了以下物品。记录集将具有以下数据:

项目ID:A005, 价格:100, 购买数量:2

项目ID:A001, 价格:80, 购买数量:2

项目ID:A006, 价格:60,, 购买数量:5

如何循环该记录集并创建以下数组

arrBought(0, 0) = "A005"
arrBought(0, 1) = 100
arrBought(0, 2) = 2

arrBought(1, 0) = "A001"
arrBought(1, 1) = 80
arrBought(1, 2) = 2

arrBought(2, 0) = "A006"
arrBought(2, 1) = 48 '20% discounted
arrBought(2, 2) = 1

arrBought(3, 0) = "A006"
arrBought(3, 1) = 60
arrBought(3, 2) = 4

这里有一个裂缝。当用户3580294引导您浏览时,基本上是一个将定期定价的单元和将折扣的单元的会计问题

dim intItemCount
dim intQtyBought
dim strItemID
dim curPrice
dim intQtyToDiscount
dim intDiscountSwitch 
intItemCount = 0
intDiscountSwitch = 0
Do While NOT RS.EOF
    strItemID = RS("ItemID")                        'More efficient than repetitively referencing the RS
    curPrice = RS("Price")
    intQtyBought = RS("QuantityBought")
    intQtyToDiscount = 0                                'Set to 0 each record
    intDiscountSwitch = intDiscountSwitch + intQtyBought
    if intDiscountSwitch >= 5 then                      'Need to process a discount
        intQtyToDiscount = intDiscountSwitch \ 5        'How many of the current item we need to discount
        intDiscountSwitch = intDiscountSwitch Mod 5     'Reset the discount switch to the remainder
        'First load the discounted items into the array
        arrBought(intItemCount, 0) = strItemID
        arrBought(intItemCount, 1) = curPrice * .8
        arrBought(intItemCount, 2) = intQtyToDiscount
        intItemCount = intItemCount + 1
    end if
    'Whether or not we had a discount, load the regular-priced items (intQtyToDiscount will be 0 if no discounted items)
    arrBought(intItemCount, 0) = strItemID
    arrBought(intItemCount, 1) = curPrice
    arrBought(intItemCount, 2) = intQtyBought - intQtyToDiscount
    RS.MoveNext
    intItemCount = intItemCount + 1
Loop

我认为在这里最好的办法是拿出可靠的铅笔和纸,研究如果有人给你任务去执行,而不是电脑,你会怎么做。从那个到伪代码,再到实际代码,应该不会太糟糕。相信我,我也一直在这么做。。。但我真的不明白。请帮忙,谢谢。事实上,没关系。给我一点…快速问一下,每个项目在记录集中是否只显示一次,或者它是否可以显示一次,然后在同一个程序中稍后显示?@user3580294每个项目在记录集中只显示一次。无论如何,请注意,如果购买的数量更大,它会更复杂,因为每5件商品都有折扣。例如,如果A006 QuantityBuyed为10,则将有2个单位,价格为48美元,8个单位,价格为60美元。