Jump to content

Calculation Issue Please Help

- - - - -

  • Please log in to reply
No replies to this topic

#1
thieflock

thieflock

    Newbie

  • Members
  • PipPip
  • 29 posts
The project is first used to calculate tax percent, sales percent, dinner price, and bill total by only typing in the dinner price and quantity. For the second part, those first calculated numbers are then totaled for the prices throughout the day. The problem is I can't get the tax percent to total, the sale percent totals just fine which means the code should be the same replaced by the variable's name. Can someone look over my code with a fresh pair of eye and try to spot the mistake (spelling, syntax, ect.)? Thank you.

    ' Dimensions module level variables and constants.

    Const TAX_AMOUNT_Decimal = 0.05D

    Const TIP_AMOUNT_Decimal = 0.15D

    Private quantitySumInteger As Integer

    Private taxAmountSumDecimal, tipAmountSumDecimal, _

    billTotalSumDecimal, averageBillDecimal As Decimal



    Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click

        ' Declare variables.

        Dim quantityInteger, quantitySum As Integer

        Dim dinnerPriceDecimal, dinnerPriceTotalDecimal, taxAmountDecimal, _

        tipAmountDecimal, billTotalDecimal, taxAmountSumDecimal, tipsSumDecimal, _

        totalBillSumDecimal, quantitySumDecimal, averageBillDecimal As Decimal



        Try

            ' Convert input to numeric.

            quantityInteger = Integer.Parse(quantityTextBox.Text)



            Try

                ' Convert price if quantity is successful.

                dinnerPriceDecimal = Decimal.Parse(dinnerPriceTextBox.Text)



                ' Calculate values.

                dinnerPriceTotalDecimal = quantityInteger * dinnerPriceDecimal

                taxAmountDecimal = Decimal.Round(dinnerPriceDecimal * TAX_AMOUNT_Decimal, 2)

                tipAmountDecimal = Decimal.Round(dinnerPriceDecimal * TIP_AMOUNT_Decimal, 2)

                billTotalDecimal = dinnerPriceTotalDecimal + taxAmountDecimal _

                + tipAmountDecimal





                ' Display calculations.

                dinnerPriceTotalLabel.Text = dinnerPriceTotalDecimal.ToString("C")

                taxAmountLabel.Text = taxAmountDecimal.ToString("C")

                tipAmountLabel.Text = tipAmountDecimal.ToString("C")

                billTotalLabel.Text = billTotalDecimal.ToString("C")



                ' Advanced calculation totals.

                quantitySumInteger += quantityInteger

                taxAmountSumDecimal += taxAmountDecimal

                tipAmountSumDecimal += tipAmountDecimal

                billTotalSumDecimal += billTotalDecimal

                averageBillDecimal = billTotalSumDecimal / quantitySumInteger

                averageBillDecimal += averageBillDecimal



                ' Display advanced calculation totals

                quantitySumLabel.Text = quantitySumInteger

                taxAmountSumLabel.Text = taxAmountSumDecimal.ToString("C")

                tipAmountSumLabel.Text = tipAmountSumDecimal.ToString("C")

                billTotalSumLabel.Text = billTotalSumDecimal.ToString("C")

                averageBillLabel.Text = averageBillDecimal.ToString("C")

            Catch dinnerPriceException As FormatException

                ' Handle the price.

                MessageBox.Show("Price must be numeric.", "Data Entry Error.", _

                MessageBoxButtons.OK, MessageBoxIcon.Exclamation)



                With dinnerPriceTextBox

                    .Focus()

                    .SelectAll()

                End With

            End Try



        Catch quantityException As FormatException

            ' Handle the quantity.

            MessageBox.Show("Quantity must be numeric.", "Data Entry Error.", _

            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            With quantityTextBox

                .Focus()

                .SelectAll()

            End With

        Catch anyException As Exception

            MessageBox.Show("Error:" & anyException.Message)

        End Try



    End Sub

Attached Files






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users