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!