Question #55404

Two fuel stops, CanadianFuel and AmericanFuel, are positioned near the U.S.–Canadian border. At the Canadian station, gas is sold by the liter. On the American side, it is sold by the gallon. Write an application that allows the user to input information from both stations and make a decision as to which station offers the most economical fuel price. Test your application with 1.259 per liter against 4.50 per gallon. Once the decision is made, display the equivalent prices. (1 liter is 0.264172 gallons)

Expert's answer

Answer on Question #55404, Programming / C#

Task: Two fuel stops, CanadianFuel and AmericanFuel, are positioned near the U.S.-Canadian border. At the Canadian station, gas is sold by the liter. On the American side, it is sold by the gallon. Write an application that allows the user to input information from both stations and make a decision as to which station offers the most economical fuel price. Test your application with 1.259 per liter against 4.50 per gallon. Once the decision is made, display the equivalent prices. (1 liter is 0.264172 gallons)

Solution:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Fuel {
public double liter(double price_gallon) {
return price_gallon*0.264172;
}
public double gallon(double price_liter) {
return price_liter/ 0.264172;
}
}
class Program
{
static void Main(string[] args)
{
Fuel ob=new Fuel();
Console.Write("Enter the fuel price per liter at the CanadianFuel stop: ");
double price_l = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the fuel price per gallon at the AmericanFuel stop: ");
double price_g = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter fuel stop: \n <1> if you are at the CanadianFuel; \n <2> if you are at AmericanFuel");
int stop = Convert.ToInt16(Console.ReadLine());
switch (stop)
{
case 1:
if (price_l < ob.liter(price_g))
{
Console.WriteLine("The price at the CanadianFuel is the most economical fuel price!");
}
if (price_l > ob.liter(price_g))
{
Console.WriteLine("The price at the AmericanFuel is the most economical fuel price!");
}
if (price_l == ob.liter(price_g))
{
Console.WriteLine("The prices are same!");
}
Console.WriteLine("The price per liter at the CanadianFuel is " + price_l + "$; \n the price per liter at the AmericanFuel is " + ob.liter(price_g) + "$");
break;
case 2:
if (price_g > ob.gallon(price_l))
{
Console.WriteLine("The price at the CanadianFuel is the most economical fuel price!");
}
if (price_g < ob.gallon(price_l))
{
Console.WriteLine("The price at the AmericanFuel is the most economical fuel price!");
}
if (price_g == ob.gallon(price_l))
{
Console.WriteLine("The prices are same!");
}
Console.WriteLine("The price per gallon at the AmericanFuel is " + price_g + "$; \n the price per gallon at the CanadianFuel is " + ob.gallon(price_l) + "$");
break;
}
Console.WriteLine();
Console.ReadLine();
}
}


http://www.AssignmentExpert.com/

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!

LATEST TUTORIALS
APPROVED BY CLIENTS