Hey guys, I'm teaching myself visual basic using the "Starting out with Visual Basic 2012" textbook and I'm having trouble with a two part programing challenge. I did the first part which was:

"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 hours 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 check box a 20% discount should be deducted from the final charges."

I'm stuck on part two, which is:

Using the previous program modify it so the form has a check box captioned Display Potential Savings. When this check box is selected, the application should also display the amount of money that package A customers would save if they purchased package B or C, or the amount that package B customers would save if they purchased package C. If there are no savings, the message should indicate that.

This chapter is about If...Then, If....Then... Else, etc. statements. I don't know where to add or start with this new information given. As well as display it as a string on a Label on the botton of the form.

Public Class Form1

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

    End Sub

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        Dim BasePrice As Decimal
        Dim Hours As Decimal
        Dim AddHours As Decimal
        Dim OverPrice As Decimal
        Dim TotalPrice As Decimal

        Hours = CDec(txtHoursUsed.Text)

        If radPackageA.Checked = True Then
            BasePrice = 9.95
            OverPrice = 2
            AddHours = Hours - 10

            If AddHours < 0 Then
                AddHours = 0
            End If

            TotalPrice = BasePrice + AddHours * OverPrice

        ElseIf radPackageB.Checked = True Then
            BasePrice = 14.95
            OverPrice = 1
            AddHours = Hours - 20

            If AddHours < 0 Then
                AddHours = 0
            End If

            TotalPrice = BasePrice + AddHours * OverPrice

        ElseIf radPackageC.Checked = True Then
            BasePrice = 19.95

            TotalPrice = BasePrice

        End If

        If chkNonprofit.Checked = True Then
            TotalPrice = BasePrice - (BasePrice * 0.2)
        End If

        lblTotalAmountDue.Text = TotalPrice.ToString("C")

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        radPackageA.Checked = True

        chkNonprofit.Checked = False


        lblTotalAmountDue.Text = String.Empty

    End Sub
End Class
1 Year
Discussion Span
Last Post by tinstaafl

Basically inside the block for each package, check if the new checkbox is checked then see if the Hours is enough to warrant a savings in the other packages. For instance in package A if the Hours is 25 it would cost 39.95 but package B would only cost 19.95, a savings of 20.00 and package C would be a savings of 20.00.

You might want to split the cost calculation into a function something like:

Private Function GetCost(packagePrice As Decimal, overCost As Decimal, hours as Decimal, limit As Integer) As Decimal

This allows you to clean up the if blocks and reduce duplicate code.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.