2.13 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3)) Ex: If the input is: 20.0

Respuesta :

Answer:

The code for this question will be:

#include <iostream>

using namespace std;

 double DrivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon) {

 

 double dollarCost = 0;

 dollarCost = (dollarsPerGallon * drivenMiles) / milesPerGallon; //calculates total cost

 

 return dollarCost;

}

int main() {

  double mileGallon = 0;

  double dollarGallon = 0;

  cin >> mileGallon;

  cin >> dollarGallon;

 

  cout << DrivingCost(10, mileGallon, dollarGallon) << " ";

  cout << DrivingCost(50, mileGallon, dollarGallon) << " ";

  cout << DrivingCost(400, mileGallon, dollarGallon) << endl;

   

  return 0;

}

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

  gallon_used = driven_miles / miles_per_gallon

  cost = gallon_used * dollars_per_gallon  

  return cost  

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Explanation:

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE