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.
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);
}
}
}
Comments
Leave a comment