家庭作業問題:互聯網服務提供商向其客戶提供三種訂閱套餐,另外 爲非營利組織提供折扣: 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