954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Could someone please help me with this logic error??

The project should display a different amount if the new release check box and the dvd {or vhs} radio button are both checked, its displaying the regular price.

This is my code:

Option Strict On

Public Class videoBonanzaSaleForm
Inherits System.Windows.Forms.Form

' Declare Constants
Const DVD_PRICE_Decimal As Decimal = 2.5D
Const NEW_RELEASE_DVD_Decimal As Decimal = 3D
Const VHS_PRICE_Decimal As Decimal = 1.8D
Const NEW_RELEASE_VHS_Decimal As Decimal = 2D
Const DISCOUNT_RATE_Decimal As Decimal = 0.1D

' Declare module-level variables.
Dim customerCountInteger As Integer
Dim grandTotalDecimal, totalDecimal, itemAmountDecimal As Decimal


Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Calculate and display the current amounts.

Dim priceDecimal, discountDecimal As Decimal

If titleTextBox.Text <> "" Then

If dvdRadioButton.Checked = True Or vhsRadioButton.Checked = True Then

' Find the price.
If dvdRadioButton.Checked Then
priceDecimal = DVD_PRICE_Decimal
ElseIf vhsRadioButton.Checked Then
priceDecimal = VHS_PRICE_Decimal
ElseIf newReleaseCheckBox.Checked And dvdRadioButton.Checked Then
priceDecimal = NEW_RELEASE_DVD_Decimal
ElseIf newReleaseCheckBox.Checked And vhsRadioButton.Checked Then
priceDecimal = NEW_RELEASE_VHS_Decimal
End If

' Calculate the extended price and add to order total.
If memberCheckBox.Checked Then
discountDecimal = priceDecimal * DISCOUNT_RATE_Decimal
Else
discountDecimal = 0
End If

itemAmountDecimal = priceDecimal - discountDecimal
totalDecimal += itemAmountDecimal

itemAmountLabel.Text = itemAmountDecimal.ToString("C")
totalLabel.Text = totalDecimal.ToString("C")
Else
MessageBox.Show("A Movies Format Must Be Selected", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else
MessageBox.Show("A Title Must Be Entered.", "Data Enrty Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
titleTextBox.Focus()
End If

' Allow a change only for a new order.
memberCheckBox.Enabled = False

' Allow clear after an order has begun.
clearButton.Enabled = True

' Reset format Radio Buttons and clear text box.
vhsRadioButton.Checked = False
dvdRadioButton.Checked = False
titleTextBox.Clear()

End Sub

Richie
Newbie Poster
3 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

Please use the [*code] and [/code] tags next time :)

Option Strict On

Public Class videoBonanzaSaleForm
Inherits System.Windows.Forms.Form

' Declare Constants
Const DVD_PRICE_Decimal As Decimal = 2.5D
Const NEW_RELEASE_DVD_Decimal As Decimal = 3D
Const VHS_PRICE_Decimal As Decimal = 1.8D
Const NEW_RELEASE_VHS_Decimal As Decimal = 2D
Const DISCOUNT_RATE_Decimal As Decimal = 0.1D

' Declare module-level variables.
Dim customerCountInteger As Integer
Dim grandTotalDecimal, totalDecimal, itemAmountDecimal As Decimal


Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
	' Calculate and display the current amounts.

	Dim priceDecimal, discountDecimal As Decimal

	If titleTextBox.Text <> "" Then

		If dvdRadioButton.Checked = True Or vhsRadioButton.Checked = True Then

			' Find the price.
			<strong>If dvdRadioButton.Checked Then
				If newReleaseCheckBox.Checked Then
					priceDecimal = NEW_RELEASE_DVD_Decimal
				Else
					priceDecimal = DVD_PRICE_Decimal
				End If
			ElseIf vhsRadioButton.Checked Then
				If newReleaseCheckBox.Checked Then
					priceDecimal = NEW_RELEASE_VHS_Decimal
				Else
					priceDecimal = VHS_PRICE_Decimal
				End If
			End If </strong>

			' Calculate the extended price and add to order total.
			If memberCheckBox.Checked Then
				discountDecimal = priceDecimal * DISCOUNT_RATE_Decimal
			Else
				discountDecimal = 0
			End If

			itemAmountDecimal = priceDecimal - discountDecimal
			totalDecimal += itemAmountDecimal

			itemAmountLabel.Text = itemAmountDecimal.ToString("C")
			totalLabel.Text = totalDecimal.ToString("C")
		Else
			MessageBox.Show("A Movies Format Must Be Selected", "Data Entry Error", _
			MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If
	Else
		MessageBox.Show("A Title Must Be Entered.", "Data Enrty Error", _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		titleTextBox.Focus()
	End If

	' Allow a change only for a new order.
	memberCheckBox.Enabled = False

	' Allow clear after an order has begun.
	clearButton.Enabled = True

	' Reset format Radio Buttons and clear text box.
	vhsRadioButton.Checked = False
	dvdRadioButton.Checked = False
	titleTextBox.Clear()

End Sub


The part I changed is in bold.
The problem was you were saying it like this:

1.IF It's a DVD or VHS THEN
1a. IF It's a DVD THEN
1a1. Set the it to regular DVD
1b. IF it's a VHS THEN
1b1. Set it to a regular VHS
1c. IF It's a New DVD
1c1. Then Set it to new dvd
1d. IF It's a new VHS THEN
1d1. Set it to a new VHS
2. END IF

Let's say a customer choose New Release VHS.
The computer would read through those instructions like this:
1. = True
1a. = False
1b. = True
1b1. it would set the value here
2.

You were thinking it would go like this:
1. = true
1a. = false
1b. = true
1b1. set the value
1c = false
1d = true
1d1. re set the value
2

Hope this helps explain it a bit :)

Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 46
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You