Jack and his three friends have decided to go for a trip by sharing the expenses of the
fuel equally. Implement a C# method CalculateCostPerPerson(double mileage, double amountPerLitre, int distanceOneWay) which returns the amount (in Rs) each of them need to put in for the complete (both to and fro) journey.
Mileage of the vehicle (km/litre of fuel) - 12
Amount per litre of fuel (Rs) - 65
Distance for one way (kms) - 96
expected output = 260
using System;
namespace trip
{
class Program
{
public static double CalculateCostPerPerson(double mileage, double amountPerLitre, int distanceOneWay)
{
var personsCount = 3;
var totalDistance = distanceOneWay * 2;
var litres = totalDistance / mileage;
var totalCost = litres * amountPerLitre;
var costPerPerson = totalCost / personsCount;
return costPerPerson;
}
static void Main(string[] args)
{
var mileage = double.Parse(Console.ReadLine());
var amountPerLitre = double.Parse(Console.ReadLine());
var distanceOneWay = int.Parse(Console.ReadLine());
var amountPerPerson = CalculateCostPerPerson(mileage, amountPerLitre, distanceOneWay);
Console.WriteLine(amountPerPerson);
}
}
}
Comments
Leave a comment