213k views
2 votes
Create a program that allows you to calculate the total cost of traveling by car to work and to print the price per person in cases where 1, 2, 3, 4, or 5 passengers are traveling. The costs to consider are the following: Distance in kilometers, Cost per liter of gasoline, Performance in kilometers per liter, Toll fees, Parking fees.

User Cbliard
by
7.7k points

1 Answer

4 votes

Final answer:

To calculate the total cost of traveling by car to work, you need to consider distance, cost per liter of gasoline, performance, toll fees, and parking fees. The total cost can be calculated using the formula Total Cost = (Distance / Performance) * Cost per liter of gasoline + Toll fees + Parking fees. The price per person can be obtained by dividing the total cost by the number of passengers.

Step-by-step explanation:

To create a program that calculates the total cost of traveling by car to work, you will need to consider several factors:

  • Distance in kilometers
  • Cost per liter of gasoline
  • Performance in kilometers per liter
  • Toll fees
  • Parking fees

To calculate the total cost, you can use the formula: Total Cost = (Distance / Performance) * Cost per liter of gasoline + Toll fees + Parking fees.

To calculate the price per person, you can divide the total cost by the number of passengers. Here are the prices per person for 1, 2, 3, 4, and 5 passengers:

  • 1 passenger: Total Cost
  • 2 passengers: Total Cost / 2
  • 3 passengers: Total Cost / 3
  • 4 passengers: Total Cost / 4
  • 5 passengers: Total Cost / 5

User Tang Jiong
by
8.4k points