家庭作业问题:互联网服务提供商向其客户提供三种订阅套餐,另外 为非营利组织提供折扣: a。套餐A:每月9.95美元的访问10小时。额外的时间是每小时$ 2.00 。 b。套餐B:每月14.95美元的20小时访问。额外的时间是 每小时1.00美元。 c。套餐C:每月19.95美元无限次使用。 d。非营利组织:服务提供商为所有非营利组织提供 所有软件包20%的折扣。 用户应该选择客户购买的包装(从一组无线电 按钮)并输入使用的小时数。一个复选框标题为Nonprofit 组织也应该出现在表单上。应用程序应计算并显示应付总金额。如果用户选择非营利组织支票 ,则应从最终费用中扣除20%的折扣。执行 注意:必须使用符号常量 (使用Const关键字)声明所有费率,限制和折扣。VB ElseIf陈述不起作用
使用以下数据,以确定应用程序是否正确地计算: 打包和小时月费 包A,5小时,非营利$ 7.96 包A 25小时$ 39.95 包B,10小时,非营利$ 11.96 套餐B 25小时$ 19.95 套餐C,18小时,非营利$ 15.96 包装℃,25小时$ 19.95
我的代码:
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Declare input and output variables
Dim intHoursUsed As Integer
Dim decTotalDue As Decimal
'Calculate Price if Package A is selected. No discount applied.
If radPackageA.Checked = True Then
If intHoursUsed < 10 Then
decTotalDue = CDec(9.95)
ElseIf intHoursUsed > 10 Then
decTotalDue = CDec((9.95) + ((intHoursUsed - 20) * 2))
End If
End If
'Calculate Price if Package B is selected. No discount applied.
If radPackageB.Checked = True Then
If intHoursUsed <= 20 Then
decTotalDue = CDec(14.95)
ElseIf intHoursUsed > 20 Then
decTotalDue = CDec((14.95) + ((intHoursUsed - 20) * 1))
End If
End If
'Calculate Price if Package C is selected. No discount applied.
If radPackageC.Checked = True Then
decTotalDue = CDec(19.95)
End If
'Declare named constant for Nonprofit Discount rate (0.8)
Const Nonprofit As Decimal = CDec(0.8)
'Add and calculate discount if checkbox is checked.
If chkNonprofit.Checked = True Then
decTotalDue = CDec(decTotalDue * Nonprofit)
End If
'Display Total Amount Due in label as string in currency format
lblTotalDue.Text = decTotalDue.ToString("c")
'Display Error Message it Hours exceed 744
If CInt(txtHoursUsed.Text) > 744 Then
MessageBox.Show("Please try again. Value must be a numeric inter and must not exceed 744.")
txtHoursUsed.Clear()
lblTotalDue.Clear()
End If
End Sub
当我计算A套餐和B套餐时,无论有多少小时,答案仅为9.95美元和14.95美元。请帮忙!我很沮丧。我无法找到什么是错的(我是一个noob)。
你能格式化你的代码吗?阅读起来并不容易。也欢迎[so],请[参观]! – Unihedron 2014-09-28 04:06:45
你在哪里为** intHoursUsed变量赋值**? – har07 2014-09-28 05:18:33