Answer to Question #213417 in C# for andy

Question #213417

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




1
Expert's answer
2021-07-04T17:12:15-0400
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);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS