I cant calculate the correct numbers via select case - vb.net

Im trying to get the discounted price using select case but i keep getting the regular price
I select student and click on yoga and personal trainer option then i put 11 months according to the calculation its supppose to be 76.50 monthly fee , total 841.50 but i get 85 monthly and total 935 . Help Thank you
Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decMontlyFee As Decimal
Dim decTotalFee As Decimal
Dim discount As Double
Dim intMonths As Integer
Dim decAdultFee As Decimal = 40
Dim decChildFee As Decimal = 20
Dim decStudentFee As Decimal = 25
Dim decSeniorFee As Decimal = 30
Dim decYogaFee As Decimal = 10
Dim decKarateFee As Decimal = 30
Dim decTrainerFee As Decimal = 50
If radAdult.Checked = True Then
decMontlyFee = decAdultFee
ElseIf radChild.Checked = True Then
decMontlyFee = decChildFee
ElseIf radStudent.Checked = True Then
decMontlyFee = decStudentFee
ElseIf radSenior.Checked = True Then
decMontlyFee = decSeniorFee
End If
If chkYoga.Checked = True Then
decMontlyFee += decYogaFee
End If
If chkTrainer.Checked = True Then
decMontlyFee += decTrainerFee
End If
If chkKarate.Checked = True Then
decMontlyFee += decKarateFee
End If
Select Case intMonths
Case Is <= 3
discount = 0
Case 4 To 6
discount = decMontlyFee * 0.05
Case 7 To 9
discount = decMontlyFee * 0.08
Case Is >= 10
discount = decMontlyFee * 0.1
End Select
decMontlyFee -= discount
decTotalFee = decMontlyFee * txtMonths.Text
lblMonthlyFee.Text = decMontlyFee.ToString("c")
lblTotalFee.Text = decTotalFee.ToString("c")
End Sub
End Class

You will need to read the value for intMonths because it is only declared and not assigned.

Assign your intMonths to the TextBox value. Simplify your syntax.
Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decMontlyFee As Decimal
Dim decTotalFee As Decimal
Dim intMonths As Integer = Integer.Parse(txtMonths.Text)
Dim decAdultFee As Decimal = 40
Dim decChildFee As Decimal = 20
Dim decStudentFee As Decimal = 25
Dim decSeniorFee As Decimal = 30
Dim decYogaFee As Decimal = 10
Dim decKarateFee As Decimal = 30
Dim decTrainerFee As Decimal = 50
decMontlyFee = If(radAdult.Checked, decAdultFee, decMontlyFee)
decMontlyFee = If(radChild.Checked, decChildFee, decMontlyFee)
decMontlyFee = If(radStudent.Checked, decStudentFee, decMontlyFee)
decMontlyFee = If(radSenior.Checked, decSeniorFee, decMontlyFee)
decMontlyFee += If(chkYoga.Checked, decYogaFee, 0)
decMontlyFee += If(chkTrainer.Checked, decTrainerFee, 0)
decMontlyFee += If(chkKarate.Checked, decKarateFee, 0)
Select Case intMonths
Case Is <= 3
decMontlyFee *= 1
Case 4 To 6
decMontlyFee *= 0.95
Case 7 To 9
decMontlyFee *= 0.92
Case Is >= 10
decMontlyFee *= 0.9
End Select
decTotalFee = decMontlyFee * intMonths
lblMonthlyFee.Text = decMontlyFee.ToString("c")
lblTotalFee.Text = decTotalFee.ToString("c")
End Sub

Related

Why can I not return the correct variables?

I'm having trouble returning the correct value for the subtotal in my application. The user selects the type of tour they want, and enters the number of tickets to be purchased. After pressing the Calculate Cost button, the subtotal, tax amount, and final total are displayed.
My code for the subtotal methods and btnCost_Click is below:
Private Sub btnCost_Click(sender As Object, e As EventArgs) Handles btnCost.Click
Dim intTicketQuantity As Integer
Dim blnNumberOfTicketsIsValid As Boolean = False
Dim blnCheckForRad As Boolean = False
Dim decSubTotal As Decimal
Dim decTotalTax As Decimal
Dim intTourType As Integer
blnNumberOfTicketsIsValid = ValidateNumberOfTickets()
If (blnNumberOfTicketsIsValid) Then
intTicketQuantity = Convert.ToInt32(txtTickets.Text)
intTicketQuantity = cboTourType.SelectedIndex
If (intTicketQuantity > 0) Then
intTourType = cboTourType.SelectedIndex
End If
Select Case intTourType
Case 0
decSubTotal = Story(intTourType, intTicketQuantity)
decTotalTax = Tax(decSubTotal)
Case 1
decSubTotal = Battleground(intTourType, intTicketQuantity)
decTotalTax = Tax(decSubTotal)
Case 2
decSubTotal = Mission(intTourType, intTicketQuantity)
decTotalTax = Tax(decSubTotal)
End Select
ShowAll(decSubTotal, decTotalTax)
End If
End Sub
Private Function Story(ByVal intTourType As Integer, intTicketQuantity As Integer) As Decimal
Dim decSubTotal As Decimal = 0D
If (radWeekday.Checked = True) Then
decSubTotal = 19D * intTicketQuantity * (1 - _decDiscount)
ElseIf (radWeekend.Checked = True) Then
decSubTotal = 19D * intTicketQuantity
End If
Return decSubTotal
End Function
Private Function Battleground(ByVal intTourType As Integer, intTicketQuantity As Integer) As Decimal
Dim decSubTotal As Decimal = 0D
If (radWeekday.Checked = True) Then
decSubTotal = 29D * intTicketQuantity * (1 - _decDiscount)
ElseIf (radWeekend.Checked = True) Then
decSubTotal = 29D * intTicketQuantity
End If
Return decSubTotal
End Function
Private Function Mission(ByVal intTourType As Integer, intTicketQuantity As Integer) As Decimal
Dim decSubTotal As Decimal = 0D
If (radWeekday.Checked = True) Then
decSubTotal = 49D * intTicketQuantity * (1 - _decDiscount)
ElseIf (radWeekend.Checked = True) Then
decSubTotal = 49D * intTicketQuantity
End If
Return decSubTotal
End Function

Why is my Select Case not working

Okay my question goes as follows; I think i coded everything right execpt for the part where i do my select case, I want the first 3 Flavours to only cost 55 cents but when I do my code it always makes the scoops 65 cents no matter what icecream type i select and i dont know how to make it change, i thought i had it right but it isnt working
Public Class frmJoeyIceCreamParlour
Const MIN_SCOOPS = 1
Const MAX_SCOOPS = 9
Const BASIC_FLAVOUR = 0.55
Const PREMIUM_FLAVOUR = 0.65
Const TOPPING = 0.6
Const DEEZ_NUTS = 0.5
Const WHIPPED_CREAM = 0.65
Public scoopEntry As Single
Public scoopType As Double
Public runningTotal As Double
Private Sub frmJoeyIceCreamParlour_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstFlavours.Items.Add("Vanilla")
lstFlavours.Items.Add("Chocolate")
lstFlavours.Items.Add("Strawberry")
lstFlavours.Items.Add("Mango")
lstFlavours.Items.Add("Bananna")
lstFlavours.Items.Add("Grape")
lstFlavours.Items.Add("Mint Chocolate Chip")
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
If txtScoops.Text = Nothing Then
MessageBox.Show("Please enter a value in the scoops category.")
txtScoops.Focus()
ElseIf Not IsNumeric(txtScoops.Text) Then
MessageBox.Show("Entry must be numeric! Please try again.")
txtScoops.Focus()
ElseIf txtScoops.Text < MIN_SCOOPS Or txtScoops.Text > MAX_SCOOPS Then
MessageBox.Show("Please enter a number between 1 and 9 scoops.")
txtScoops.Focus()
ElseIf lstFlavours.SelectedItem = Nothing Then
MessageBox.Show("Please select a flavour.")
ElseIf rdoNoTopping.Checked = False And rdoOneTopping.Checked = False And rdoTwoTopping.Checked = False And rdoThreeTopping.Checked = False Then
MessageBox.Show("Please select the amount of toppings you would like.")
Else
Dim number As Integer = 7
Select Case number
Case 1 To 3
scoopType = BASIC_FLAVOUR
Case 4 To 7
scoopType = PREMIUM_FLAVOUR
runningTotal = scoopType * Double.Parse(txtScoops.Text)
End Select
If rdoOneTopping.Checked = True Then
runningTotal = runningTotal + TOPPING
ElseIf rdoTwoTopping.Checked = True Then
runningTotal = runningTotal + (TOPPING * 2)
ElseIf rdoThreeTopping.Checked = True Then
runningTotal = runningTotal + (TOPPING * 3)
End If
If chkWhippedCream.Checked = True Then
runningTotal = runningTotal + WHIPPED_CREAM
End If
If chkNuts.Checked = True Then
runningTotal = runningTotal + DEEZ_NUTS
End If
lblOutputTotal.Text = (FormatCurrency(runningTotal))
End If
End Sub
End Class
You have it hard coded to use 7 via the line just above your Select case number statement: Dim number As Integer = 7. You should instead be looking up the selected index by doing something like Dim number As Integer = lstFlavours.SelectedIndex
Dim number As Integer = lstFlavours.SelectedIndex
Select Case number
Case 1 To 3
scoopType = BASIC_FLAVOUR
Case 4 To 7
scoopType = PREMIUM_FLAVOUR
End Select
runningTotal = scoopType * Double.Parse(txtScoops.Text)

VB2013, Possible Arithmetic Error

In Shadowrun 5e there is a rule concerning explosives in confined spaces called the 'Chunky Salsa Effect'. I am trying to create a program that simulates the 'Chunky Salsa Effect'. I have most of the program working, however, as the size of the space [meters] increases, the number of blast reflections [bounces] increases. It should be the inverse, the blast falloff [minusMeters] should decrease the [bounces]. [walls] determines the number of surfaces the blast reflects off of. [damageDice] is equal to the base damage of the explosive [baseDamageDice] + (([damageDice]/2) per reflection). For some reason [damageDice] and [bounces] do not decrease when [meters] is increased.
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim meters As Integer = 0
Dim dice As Integer = 0
Dim damageDice As Integer = 0
Dim baseDamageDice As Integer = 0
Dim bounces As Integer = 0
Dim hits As Integer = 0
Dim walls As Integer = 0
Dim minusMeters As Integer = 0
Dim explosiveType As Integer = 0
Dim ap As String = "-"
Dim diceRoll As Integer = 0
Randomize()
walls = CInt(txtWalls.Text)
explosiveType = cbExplosiveType.SelectedIndex
If explosiveType < 0 Then
explosiveType = 0
cbExplosiveType.SelectedIndex = 0
End If
Select Case explosiveType
Case 0
minusMeters = 1
baseDamageDice = 18
ap = "+5"
Case 1
minusMeters = 2
baseDamageDice = 16
ap = "-2"
Case 2
minusMeters = 4
baseDamageDice = 24
ap = "-4"
Case 3
minusMeters = 4
baseDamageDice = 24
ap = "-10"
Case 4
minusMeters = 1
baseDamageDice = 23
ap = "+5"
Case 5
minusMeters = 2
baseDamageDice = 21
ap = "-2"
End Select
diceRoll = CInt(Math.Floor((6 - 1 + 1) * Rnd())) + 1
If diceRoll >= 5 Then
hits = hits + 1
End If
dice = baseDamageDice
For x = 1 To walls
meters = CInt(txtMeters.Text)
damageDice = baseDamageDice
Do
damageDice = Math.Round(damageDice / 2)
dice = dice + damageDice
meters = meters - minusMeters
bounces = bounces + 1
Loop While meters >= 0
Next
For i As Integer = 1 To dice
diceRoll = CInt(Math.Floor((6 - 1 + 1) * Rnd())) + 1
If diceRoll >= 5 Then
hits = hits + 1
End If
Next
lblHitsPerBounce.Text = Math.Round(hits / bounces)
lblTimes.Text = bounces
lblResult.Text = dice
lblNumHits.Text = hits
lblAPOutput.Text = ap
End Sub

How to make a "key generator" knowing the formula

I have the formula to check 9 integers,
First digit(d1) must be: 1, 2, 5, 6, 8 or 9
Last digit(d9) must be: 0 or 9
9xd1+8xd2+7xd3+6xd4+5xd5+4xd6+3xd7+2xd8+d9 mod 11 = 0
I can "validate" the key, but how can I generate more of this, knowing the conditions for it to be right?
How can I generate 9 different integers from 0 to 9 and check them under this formula?
Thanks for helping!
Generate the first 7 digits randomly, calculating the formula for those digits.
Set the 9th digit's value to 9, and add it to the formula.
Calculate a value for the 8th digit based on the mod of the result of the formula that causes the result of the formula to be mod 11 = 0.
For the exception case where attempting to do this causes mod 11 = 9, set the 9th digit to 0.
Implementation:
Private randGen As New Random()
Function GenNum() As Integer
Dim digits(0 To 8) As Integer
GenNum = 0
Dim checkSum As Integer
digits(0) = randGen.Next(6) + 1
If digits(0) >= 3 Then digits(0) += 2
If digits(0) >= 7 Then digits(0) += 1
checkSum += digits(0) * 9
For d As Integer = 1 To 6
digits(d) = randGen.Next(10)
checkSum += digits(d) * (9 - d)
Next
digits(8) = 9
checkSum += digits(8)
If (checkSum Mod 11) Mod 2 = 1 Then
digits(7) = (11 - (checkSum Mod 11)) \ 2
Else
digits(7) = ((12 - (checkSum Mod 11)) \ 2 + 4) Mod 10
End If
checkSum += digits(7) * 2
If checkSum Mod 11 = 9 Then digits(8) = 0
Dim pow10 As Integer = 1
For d As Integer = 8 To 0 Step -1
GenNum += pow10 * digits(d)
pow10 *= 10
Next
End Function
I can help you to generate integers from 0 to 9.
here is how your form should look like:
and here is the code:
Public Class Form1
Dim NumRandom As Random = New Random
Dim X, Y, Z As Integer
Private Sub GenerateBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateBUT.Click
Dim a(9), i, j, RN As Integer
Dim flag As Boolean
flag = False
i = 1
a(j) = 1
Do While i <= 9
Randomize()
RN = CInt(Int(9 * Rnd()) + 1)
For j = 1 To i
If (a(j)) = RN Then
flag = True
Exit For
End If
Next
If flag = True Then
flag = False
Else
a(i) = RN
i = i + 1S
End If
Loop
Label1.Text = a(1)
Label2.Text = a(2)
Label3.Text = a(3)
Label4.Text = a(4)
Label5.Text = a(5)
Label6.Text = a(6)
Label7.Text = a(7)
Label8.Text = a(8)
Label9.Text = a(9)
Z = Label4.Text
Y = Label5.Text
X = Z + Y
X = X - Label3.Text
If X > 1 And X < 10 Then
X = NumRandom.Next(1, 7)
If X = 1 Then
Label1.Text = "0"
ElseIf X = 2 Then
Label2.Text = "0"
ElseIf X = 3 Then
Label3.Text = "0"
ElseIf X = 4 Then
Label4.Text = "0"
ElseIf X = 5 Then
Label5.Text = "0"
ElseIf X = 6 Then
Label6.Text = "0"
ElseIf X = 7 Then
Label7.Text = "0"
End If
End If
End Sub
End Class

VB Simple If statements (h/w)

I don't deal with VB. I am helping my mother with her homework and just cant think straight anymore on what to do with this statement.
Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click
Dim intPackA As Integer = 0
Dim intPackB As Integer = 0
Dim intPackC As Integer = 0
Dim SavingsPriceB As Decimal = 0.0
Dim SavingsPriceC As Decimal = 0.0
Dim TotalPrice As Decimal = 0.0
lblTotal.Text = String.Empty
If radPackA.Checked Then
TotalPrice = 9.95
lblTotal.Text = TotalPrice
If Integer.TryParse(txtHours.Text, intPackA) Then
If intPackA > 10 Then
TotalPrice = TotalPrice + ((intPackA - 10) * 2)
lblTotal.Text = TotalPrice
End If
End If
If chkSavings.Checked Then
SavingsPriceB = 14.95 + ((intPackB - 20) * 1)
SavingsPriceC = 19.95
If TotalPrice < SavingsPriceB And TotalPrice < SavingsPriceC Then
lblTotal.Text = TotalPrice & ", no savings with Package B or C"
End If
End If
ElseIf radPackB.Checked Then
TotalPrice = 14.95
lblTotal.Text = TotalPrice
If Integer.TryParse(txtHours.Text, intPackB) Then
If intPackB > 20 Then
TotalPrice = TotalPrice + ((intPackB - 20) * 1)
lblTotal.Text = TotalPrice
End If
End If
If chkSavings.Checked Then
End If
ElseIf radPackC.Checked Then
TotalPrice = 19.95
lblTotal.Text = TotalPrice
End If
If chkNonprofit.Checked Then
TotalPrice = Format((TotalPrice - ((TotalPrice / 100) * 20)), ".00")
lblTotal.Text = TotalPrice & ControlChars.CrLf & "Non-Profit Organization discount applied"
End If
End Sub
It's the If chkSavings.Checked that's giving me problem.
This is the program as designed. There is a label bellow the packages that displays the total.
When the Potential Savings is checked, it should also display the amount you could save if you use a different package.
So if I put Package A, 5 hours, 20% discount it should say $7.96, no savings with Package B or C. For Package A, 25 hours it should say $39.95, save $20.00 with Package B, and save $20.00 with Package C
The code I have does not print it even the first part.
Package A and less then 10 hours = $9.95, every additional hour is $2.00 more
Package B and less then 20 hours = $14.95, every additional hour is $1.00 more
Package C with unlimited hours is = $19.95
So My question is, what am I doing wrong in my code or how could I achieve what I am looking for.