# Visual Basic Percentage Discount Help?



## huggies12345

I am doing a visual basic university project.
I have to deisgn and code a cinema booking system.
I am stuck and hoping that someone can help.

I am trying to make discounts for prices.

Firstly, i have radio buttons one that gives 10% discount and one that gives 25% discount, i have a "Number of seats textbox" which the user types in the number of seats they want to book and a price label (lbl6) that will display the overall price.

I am using this code to work out the price for how many seats the user puts in:

Lbl6.Text = FormatCurrency(Lbl6.Text * seats)

This is working fine.

I am using this code for the discount this will take away the percentage from the price:

If RadioButton2.Checked Then
Lbl6.Text = FormatCurrency(Lbl6.Text - Lbl6.Text * seats / 100 * 10)
ElseIf RadioButton3.Checked Then
Lbl6.Text = FormatCurrency(Lbl6.Text - Lbl6.Text * seats / 100 * 25)

End If

The first line is to take off a 10% discount.
The second line is to take off a 25% discount.

Now my problem is that when i type "1" in the number of seats box and press a discount button it works fine, but when i type any "2" in the seats box, it will find 20% instead of 10%.

Can anyone please tell me why this is happening?

I have tried putting brackets in different places but still it doesn't work.

Hope Someone can understand what i am talking about.


----------



## Sess

My advice would be to set a constant on the module level such as...

Private TEN_DISCOUNT_Decimal As Decimal = .1D
Private TWENTY_DISCOUNT_Decimal As Decimal = .25D

Then in the sub section declare a local variable to hold the prices

Dim Seats As Integer
Dim TotalDiscount As Decimal
Dim TotalCost As Decimal

from there we parse the seats integer in

Seats = Integer.Parse(seatstextbox.text)

Then calculations
If RadioButton2.checked = True then
TotalDiscount = (Lbl6 * Seats) * TEN_DISCOUNT_Decimal
ElseIf RadioButton3.checked = true then
TotalDiscount = Seats * TWENTY_DISCOUNT_Decimal
EndIf

TotalCost = (Lbl6 * Seats) - TotalDiscount

I didn't test the math but I'm fairly sure I covered all the steps.


----------



## stubacca

Of all the people to find on this forum to answer one of the many questions that plague me the night before it's due in, I truly am shocked, wish I had decided to do this much earlier....


----------

