# how to calculate sales tax and amount due.

Page 1 of 1

## 1 Replies - 9158 Views - Last Post: 28 November 2013 - 11:34 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=335235&amp;s=4e96032fe6e913929aaeae75c5157c4d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 glb482417

Reputation: 0
• Posts: 6
• Joined: 28-November 13

# how to calculate sales tax and amount due.

Posted 28 November 2013 - 11:06 PM

Iam trying to calculate a sales tax and amount due i am stuck. Ihave a pizza order form to get the sales tax you have (toppingsDecimal + pizzaDecimal - DiscountDecimal)* SalesTax_Rate_Decimal you have two discount oppitions 10% and 15% to choose from how can i do this where is my code wrong it calculates the 15% discount but not the 10% discount please help if you can. I am using Visual Basic 2010

```Public Class MamaJanesForm
' Declare a named constant.
Const Peppers_Charge_Decimal As Decimal = 0.75D
Const Onions_Charge_Decimal As Decimal = 0.75D
Const ExtraCheese_Charge_Decimal As Decimal = 0.75D
Const Coupon_Rate_Decimal As Decimal = 0.1D
Const PreferredCustomer_Rate_Decimal As Decimal = 0.15D
Const SalesTax_Rate_Decimal As Decimal = 0.08D
Dim ToppingsDecimal, DiscountDecimal, PizzaDecimal, SalestaxDecimal As Decimal
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
' Change the font name for the label.
With FontDialog1
.ShowDialog()
AmountDueLabel.Font = .Font
End With
End Sub

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
' Change the color of the amount due label.
With ColorDialog1
.ShowDialog()
AmountDueLabel.ForeColor = .Color
End With
End Sub

Dim MessageString As String
' Display the message box.
MessageString = "Mama Jane's Pizza" & Environment.NewLine & "Programmed by Gary Brewster"
MessageBox.Show(MessageString, "About Mama Jane's Pizza", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
' Terminate the program.
Me.Close()
End Sub

Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
Dim ToppingsDecimal, DiscountDecimal, PizzaDecimal, SalestaxDecimal, AmountDueDecimal As Decimal
' Look up pizza rate.
Dim SizeIndexInteger As Integer
Dim StyleIndexInteger As Integer
Dim pizzaArrayDecimal(,) As Decimal = {{5.99, 6.99, 7.99, 8.99}, _
{6.99, 7.99, 8.99, 9.99}}

SizeIndexInteger = SizeComboBox.SelectedIndex
StyleIndexInteger = StyleComboBox.SelectedIndex
If SizeIndexInteger <> -1 And StyleIndexInteger <> -1 Then
PizzaTextBox.Text = pizzaArrayDecimal(SizeIndexInteger, StyleIndexInteger).ToString
End If
'Include the Toppings charges.
If CheckBox1.Checked Then
ToppingsDecimal += Peppers_Charge_Decimal
End If
If CheckBox2.Checked Then
ToppingsDecimal += Onions_Charge_Decimal
End If
If CheckBox3.Checked Then
ToppingsDecimal += ExtraCheese_Charge_Decimal
End If

DiscountDecimal = Coupon_Rate_Decimal * (PizzaDecimal + ToppingsDecimal)

DiscountDecimal = PreferredCustomer_Rate_Decimal * (PizzaDecimal + ToppingsDecimal)
Try
'Calculate sales tax
SalestaxDecimal = ((ToppingsDecimal + PizzaDecimal) - DiscountDecimal) * SalesTax_Rate_Decimal
Catch
End Try
' Find the total.
AmountDueDecimal = ToppingsDecimal + PizzaDecimal + DiscountDecimal + SalestaxDecimal

End If
'Display amounts in labels
ToppingsTextBox.Text = ToppingsDecimal.ToString("C")
DiscountTextBox.Text = DiscountDecimal.ToString("C")
SalesTaxTextBox.Text = SalestaxDecimal.ToString("C")

End Sub

Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
' Clear all information.
NameTextBox.Clear()
CityTextBox.Clear()
StateTextBox.Clear()
zipTextBox.Clear()
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
SizeComboBox.SelectedIndex = -1
StyleComboBox.SelectedIndex = -1
PizzaTextBox.Clear()
ToppingsTextBox.Clear()
DiscountTextBox.Clear()
SalesTaxTextBox.Clear()
AmountDueTextBox.Clear()
NameTextBox.Focus()
End Sub

End Class

```

Is This A Good Question/Topic? 0

## Replies To: how to calculate sales tax and amount due.

### #2 astonecipher

• Senior Systems Engineer

Reputation: 2483
• Posts: 9,965
• Joined: 03-December 12

## Re: how to calculate sales tax and amount due.

Posted 28 November 2013 - 11:34 PM

Try

```RadioButton2.Checked = true
```

And your try statement is of no value to you without something in the catch block.

It would also behoove you to name your controls so that you know what they correspond to, you do it for your variables but not all of your controls.

This post has been edited by astonecipher: 28 November 2013 - 11:37 PM