Hi! I am trying to create a program that can calculate the cost of a internet package once selected and also give a discount. So far, my code only works with doesn't exactly gove me the correct results. Below is my code. Please assist me in identifying the problem.

An internet service provicer offers 3 subscriptions packages to its customers, plus a discount for nonprofit organizations
a) packaga A: 10 hours of access for $9.95 per month. Additional hpurs are $2.00 per hour.
b)package B: 20 Hours of access for $14.95 per month. Additional hpurs are $1.00 per hpur
c)package C: Unlimited access for $19.95 per month
d)Nonprofit Organizations: the service provider gives all nonprofit prganizations 20% discount on all packages
the user should selelct the package the customer has purchased(from a set of radio buttons) and enter the number of hpurs used> a check box captioned nonprofit organization should also appear on the form. the application should calculateand display the total amount due. if user selects the nonprofit organization chek box a 20
% discount should be deducted from the final charges. implementation note: all rates, and discounts must be declared using simbolic constats(using the keyboard const)
input validation": the number if hpours used in a month cannot excees 744.. the value must be numeric

Public Class Form1

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim decBaseFee As Decimal
Const decDiscount As Decimal = 0.2D
Dim decTotalFee As Decimal
Dim intHoursUsed As Integer

If Not Integer.TryParse(txtHoursUsed.Text, intHoursUsed) Then
MessageBox.Show("The number of hours exceeds the limit ", "Input Error")
Return

End If

If (intHoursUsed < 1) Or (intHoursUsed > 744) Then
MessageBox.Show("The number of hours exceeds the limit", "Inpuy Error")
Return
End If

If radPackageA.Checked = True Then
decBaseFee = CDec(9.95)

If (intHoursUsed > 10) Then
decTotalFee = CDec(9.95 + (intHoursUsed + 10) * 2.0)

End If

ElseIf radPackageB.Checked = True Then
decBaseFee = CDec(14.95)

If (intHoursUsed > 20) Then
decTotalFee = CDec(14.95 + (intHoursUsed - 20) * 1.0)

End If


ElseIf radPackageC.Checked = True Then
decBaseFee = CDec(19.95)

End If

If chkNonprofit.Checked = True Then
decTotalFee = decBaseFee * decDiscount - decBaseFee

End If


lblTotalAmountDue.Text = decTotalFee.ToString("c")

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
radPackageA.Checked = True
radPackageB.Checked = True
radPackageC.Checked = True
txtHoursUsed.Clear()
txtCode.Clear()
lblNumberofHours.Text = String.Empty
lblTotalAmountDue.Text = String.Empty

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()
End Sub
End Class

I would suggest the following changes (in red):

Public Class Form1

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim decBaseFee As Decimal
Const decDiscount As Decimal = 0.8D
Dim decTotalFee As Decimal
Dim intHoursUsed As Integer

If Not Integer.TryParse(txtHoursUsed.Text, intHoursUsed) Then
MessageBox.Show("The number of hours exceeds the limit ", "Input Error")
Return

End If

If (intHoursUsed < 1) Or (intHoursUsed > 744) Then
MessageBox.Show("The number of hours exceeds the limit", "Input Error")
Return
End If

If radPackageA.Checked or radPackageB.Checked or radPackageC.Ckecked Then
If radPackageA.Checked = True Then
decBaseFee = CDec(9.95)

If (intHoursUsed > 10) Then
decBaseFee = CDec(9.95 + (intHoursUsed - 10) * 2.0)

End If

ElseIf radPackageB.Checked = True Then
decBaseFee = CDec(14.95)

If (intHoursUsed > 20) Then
decBaseFee = CDec(14.95 + (intHoursUsed - 20) * 1.0)

End If


ElseIf radPackageC.Checked = True Then
decBaseFee = CDec(19.95)



End If

If chkNonprofit.Checked = True Then
decDiscount = 1.0D
End If

decTotalFee = decBaseFee * decDiscount 

lblTotalAmountDue.Text = decTotalFee.ToString("c")
Else
MessageBox.Show("Must select one package option", "Input Error")
End If
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
radPackageA.Checked = False
radPackageB.Checked = False
radPackageC.Checked = False
txtHoursUsed.Clear()
txtCode.Clear()
lblNumberofHours.Text = String.Empty
lblTotalAmountDue.Text = String.Empty

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()
End Sub
End Class

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.