1 Replies - 1018 Views - Last Post: 18 April 2018 - 12:55 AM Rate Topic: -----

#1 Asherjb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-April 18

Travel expense calculator

Posted 17 April 2018 - 05:07 PM

Hey I'm having trouble with my assignment my math is wrong somewhere but cant figure it out any help is appreciated!

Create an application that calculates and displays the total travel expenses for a business trip. The user must provide the following information:

Number of days on the trip
amount of airfare, if any
amount of car rental fees, if any
number of miles driven , if a private vehicle was used
amount of parking fees , if any
amount of taxi charges, if any
conference or seminar registration fees, if any
lodging charges, per night
The company reimburses travel expenses according to the following policy:
- 37 per day for meals
-Parking fees, up to $10.00 per day
-Taxi Charges up to $20.00 per day
-Lodging charges up to $95.00 per day
-If a private vehicle is used, $0.27 per mile driven

The application should calculate and display the following:
-Total expenses incurred by the business person
-The total allowable expenses for the trip
-The excess that must be paid by the business person, if any
-The amount saved by the the business person if the expenses were under the total allowed.

the applications should have the following function:
CalcMeals Calculates and returns the amount reimbursed for meals.
CalcMileage Calculates and returns the amount reimbursed for mileage driven in a private vehicle
CalcParking Fees calculates and returns the amount reimbursed for parking fees
CalcTaxiFees Calculates and returns the amount reimbursed for taxi charges
CalcLodging Calculates and returns the amount reimbursed for lodging
CalcTotalReimbursement Calculates and returns the total amount reimbursed
CalcUnallowed Calculates and returns the total amount of expenses that are not allowable, if any. These are parking fees that exceed $10.00 per day, taxi charges that exceed $20.00 per day and lodging charges that exceed $95.00 per day
CalcSaved Calculates and returns the total amount of expenses under the allowable amount, if any . For example, the allowable amount for lodging is $95.00 per day. If a business person stayed in a hotel for $85.00 per day for five days, the savings would $50.00

Input Validation-
Do not accept negative numbers for any dollar amount or for miles driven in a private vehicle. Do not accept numbers less that 1 for the number of days.

Here is my code so far.

Public Class Form1
    'Constants for allowed spending
    Const decMEALS As Decimal = 37D
    Const decPARKING As Decimal = 10D
    Const decTAXI As Decimal = 20D
    Const decLODGING As Decimal = 95D
    Const deCMILES As Decimal = 0.27D

    Function CalcLodging() As Decimal

        Dim decLodge As Decimal
        If txtLodging.Text = String.Empty Then
            decLodge = 0
            decLodge = (CDec(txtDays.Text) * decLODGING)
        End If
        Return decLodge
    End Function
    Function CalcMeals() As Decimal
        Dim decmeal As Decimal
        If txtMeals.Text = String.Empty Then
            decmeal = 0
            decmeal = (CDec(txtDays.Text) * decMEALS)
        End If
        Return decmeal
    End Function
    Function CalcMileage() As Decimal
        Dim decMileage As Decimal
        If txtMiles.Text = String.Empty Then
            decMileage = 0
            decMileage = (CDec(txtMiles.Text) * deCMILES)
        End If
        Return decMileage
    End Function
    Function CalcParkingFees() As Decimal
        Dim decPark As Decimal
        decPark = CDec(txtDays.Text) * decPARKING
        Return decPark
    End Function
    Function CalcTaxiFees() As Decimal
        Dim decTaxifee As Decimal
        decTaxifee = decTAXI * CDec(txtDays.Text)
        Return decTaxifee
    End Function

    Function CalcTotalReimbursement() As Decimal
        Dim decTotals As Decimal
        decTotals = CalcLodging() + CalcTaxiFees() +
        CalcMeals() + CalcParkingFees()
        Return decTotals
    End Function
    Function CalcUnallowed() As Decimal
        Dim decUnallowed As Decimal
        decUnallowed = (CDec(txtParking.Text) - CalcParkingFees()) +
(CDec(txtTaxi.Text) - CalcTaxiFees()) + (CDec(txtLodging.Text) - CalcLodging()) +
(CDec(txtMeals.Text) - CalcMeals())
        Return decUnallowed
    End Function
    Function CalcSaved() As Decimal
        Dim decSaved As Decimal
        decSaved = (CDec(txtDays.Text) * decMEALS - CDec(txtMeals.Text)) +
(CDec(txtDays.Text) * decPARKING - CDec(txtParking.Text)) +
(CDec(txtDays.Text) * decTAXI - CDec(txtTaxi.Text)) +
(CDec(txtDays.Text) * decLODGING - CDec(txtLodging.Text))
        Return decSaved
    End Function

    Function CalcTotal() As Decimal
        Dim decTotal As Decimal
        decTotal = CDec(txtAirFare.Text) + CDec(txtRegistration.Text) + CDec(txtMeals.Text) +
        (CDec(txtMiles.Text) * deCMILES) + CDec(txtCarRental.Text) +
        CDec(txtLodging.Text) + CDec(txtParking.Text) + CDec(txtTaxi.Text)
        Return decTotal
    End Function

    Sub InputEmpty()
        If txtAirFare.Text = String.Empty Then
            txtAirFare.Text = "0"
        End If
        If txtCarRental.Text = String.Empty Then
            txtCarRental.Text = "0"
        End If
        If txtDays.Text = String.Empty Then
            MessageBox.Show("Enter a Positive Amount of Days")
        End If
        If txtLodging.Text = String.Empty Then
            txtLodging.Text = "0"
        End If
        If txtMeals.Text = String.Empty Then
            txtMeals.Text = "0"
        End If
        If txtMiles.Text = String.Empty Then
            txtMiles.Text = "0"
        End If
        If txtParking.Text = String.Empty Then
            txtParking.Text = "0"
        End If
        If txtRegistration.Text = String.Empty Then
            txtRegistration.Text = "0"
        End If
        If txtTaxi.Text = String.Empty Then
            txtTaxi.Text = "0"
        End If
        If lblResponsible.Text = String.Empty Then
            lblResponsible.Text = "0"
        End If
        If lblSaved.Text = String.Empty Then
            lblSaved.Text = "0"
        End If
        If lblTotal.Text = String.Empty Then
            lblTotal.Text = "0"
        End If
        If lblTotalAllowable.Text = String.Empty Then
            lblTotalAllowable.Text = "0"
        End If
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        If CalcTotalReimbursement() > 0 Then
                    lblTotalAllowable.Text = CStr(CalcTotalReimbursement().ToString("c"))
                    lblTotalAllowable.Text = String.Empty
                End If
                If CalcTotal() > 0 Then
                    lblTotal.Text = CStr(CalcTotal().ToString("c"))
                    lblTotal.Text = String.Empty
                End If
                If CalcUnallowed() > 0 Then
                    lblResponsible.Text = CStr(CalcUnallowed().ToString("c"))
                    lblResponsible.Text = String.Empty
                End If
                If CalcSaved() > 0 Then
                    lblSaved.Text = CStr(CalcSaved().ToString("c"))
                    lblSaved.Text = String.Empty
                End If

    End Sub
    Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click
        txtAirFare.Text = String.Empty
        txtCarRental.Text = String.Empty
        txtDays.Text = String.Empty
        txtLodging.Text = String.Empty
        txtMeals.Text = String.Empty
        txtMiles.Text = String.Empty
        txtParking.Text = String.Empty
        txtRegistration.Text = String.Empty
        txtTaxi.Text = String.Empty
        lblResponsible.Text = String.Empty
        lblSaved.Text = String.Empty
        lblTotal.Text = String.Empty
        lblTotalAllowable.Text = String.Empty
    End Sub
    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Travel expense calculator

#2 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6667
  • View blog
  • Posts: 27,299
  • Joined: 12-December 12

Re: Travel expense calculator

Posted 18 April 2018 - 12:55 AM

You have 166 lines of code there. Give us some guidance. What specific issue are you having and whereabouts in your code?
Provide sample input and output: both expected and actual output.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1