Answer to Question #303430 in C# for Rakshith

Question #303430

Problem Statement:



Jack and his three friends have decided to go for a trip by sharing the expenses of the



fuel equally. Implement a C# method Calculate CostPerPerson(double mileage,



double amountPerLitre, int distanceOne Way) which returns the amount (in Rs) each



of them need to put in for the complete (both to and fro) journey.

1
Expert's answer
2022-03-01T07:12:24-0500
using System;

namespace CostperPerson
{
    class Program
    {        
        public static double CostPerPerson(double mileage, double amountPerLitre, int distanceOneWay)
        {
            double Rs;
            Rs = distanceOneWay / mileage * amountPerLitre;
                    
            return Rs;
           }
        
        public static void Main(string[] args)
        {
            double amount;
            Console.Write("Enter mileage: ");
            double mil = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter amount per litre: ");
            double apl = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter distance one way: ");
            int dow = Convert.ToInt32(Console.ReadLine());
            amount = (CostPerPerson(mil, apl, dow) * 2) / 3;
            Console.WriteLine();
            Console.WriteLine("Amount: {0:f2}", amount);
            Console.WriteLine();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

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