Question: Hello, I need help with this exercise. I am a beginner using Visual Studio 2015 program and am doing all the exercises starting from chapter
Hello, I need help with this exercise. I am a beginner using Visual Studio 2015 program and am doing all the exercises starting from chapter 1 from the Microsoft Visual Basic 2015 RELOADED book. Here is the code I currently have and this is what I need.
What I need:
Before displaying the total price, use a message box to determine whether the customer is entitled to a 10% discount for being a member of the Book Shack Club.
Here is my code so far:
__________________________________________________________________________________________________________
Option Explicit On Option Strict On Option Infer Off
Public Class Form1 Private Sub booksTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles booksTextBox.KeyPress
' accept only numbers and the backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then e.Handled = True End If End Sub
Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click
' calculate the total price
Const Price1To3 As Double = 2.99 Const Price4To6 As Double = 2.49 Const PriceOver6 As Double = 1.75 Dim numBooks As Integer Dim totalPrice As Double Dim button As DialogResult
' parse booksTextBox
Integer.TryParse(booksTextBox.Text, numBooks) Select Case numBooks Case 1 To 3 totalPrice = Price1To3 * numBooks Case 4 To 6 totalPrice = Price4To6 * numBooks Case Is > 6 totalPrice = PriceOver6 * numBooks button = MessageBox.Show("$1 coupon?", "Book Shack", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If button = DialogResult.Yes Then totalPrice -= 1 End If End Select totalLabel.Text = totalPrice.ToString("C2") booksTextBox.Focus() End Sub
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
' close application
Me.Close()
End Sub End Class
__________________________________________________________________________________________________________
Thank you soooo much for your help!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
