问题描述
我正在制作一个应用程序来显示订单的总价.它根据订购的商品数量以及客户是批发商还是零售商来决定价格.
I'm making an application to display the total price of a order. It decides the price based on the number of items ordered and if the customer is a wholesale or retailer.
它使用的计算:
1-4 件商品 = 批发商每件 10 美元.
1-4 items = $10 per item if wholesaler.
如果是批发商,5 件以上 = 每件 9 美元.
5+ items = $9 each if wholesaler.
1-3 件商品 = 每件 15 美元(如果是零售商).
1-3 items = $15 per item if retailer.
4-8 件 = 每件 14 美元(如果是零售商).
4-8 item = $14 per item if retailer.
9+ 件 = 每件 12 美元(如果是零售商).我被困在计算上,不知道该怎么做.
9+ item = $12 per item if retailer.I'm stuck on the calculation and confused as to how I would do it.
GUI 已完成,这是我目前所拥有的:
The GUI is complete, here is what I have so far:
图形界面图片:http://i.imgur.com/P2tDz.png
Dim quantity As Decimal
Dim price As Decimal
Dim wholesaler As Integer
Dim retailer As Integer
Integer.TryParse(txtUnits.Text, price)
chkRetailer.Text = retailer
chkWholesale.Text = wholesaler
If wholesaler Then
If Quantity <= 4 Then
Price = 10
Else
Price = 9
End If
ElseIf retailer Then
If Quantity <= 3 Then
Price = 15
ElseIf Quantity <= 8 Then
Price = 14
Else
Price = 12
End If
End If
lblTotPrice.Text = price * quantity
lblTotPrice.Text = price.ToString("C0")
这是我困惑的计算,我相信我的显示和声明是正确的.
It's the calculation I'm confused on, I have the display and the declarations correct I believe.
谢谢.
推荐答案
使用 Case statements(提供的链接的VB示例非常有用)
This would be much clearer using Case statements (The VB example of the link provided is very helpful)
首先使用 IF
语句来确定您是否是批发商,并确定两个 case 语句中的哪一个指定了有效价格
First use an IF
statement to determine if you are a wholesaler and that determines which of the two case statements assigns the valid price
这篇关于VB.net 价格计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!