ANSWER IN C++ PLEASE!!!!!
Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) 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 by executing
cout << fixed << setprecision(2); once before all other cout statements. Note: End with a newline.

Respuesta :

tonb

Answer:

#include <iostream>

#include <iomanip>  

using namespace std;

int main()

{

   double mpg, ppg;

   cout << "Enter your car's gas mileage (miles/gallon): ";

   cin >> mpg;

   cout << "Enter the gas price (dollars/gallon): ";

   cin >> ppg;

   cout << fixed << setprecision(2);

   for (int miles : { 20,75,500 }) {

       cout << miles << " miles will cost $" << miles * ppg / mpg << endl;

   }

}

Explanation:

I really like the new for(x:y) construct!