[College C++] Coding help

Lets break down the problem first:

determine the average miles per gallon for a car when driven in town and the average miles per gallon when driven only on the interstate (highway).

So you're on the right track but we need the average for both city and highway.

cityMiles 
highwayMiles

will replace the variable miles.

formula: Distance = Number of Gallons X Average Miles per Gallon

Here is the formula given to calculate miles. From the formula we need to ask the use for input.

cityMiles = gallons * cityMPG;  //gallons and cityMPG are both entered by user for both city and highway
highwayMiles = gallons * highwayMPG; 

Notice we created two new variables, cityMPG and highwayMPG.

Lastly, we were given some more information. A car with a 20 gallon tank will get a different MPG on the highway than it will in the city. So that's why we have two formulas to calculate distance. On the highway, we can travel more on a 20 gallon tank.

The test car has a 20-gallon gas tank. The car averages 23.5 miles per gallon when driven in town. The same car gets 28.9 miles per gallon when driven on the highway.

Write a C++ program that calculates and displays the distance the car can travel on one tank of gas when driven in town and also when driven on the highway.

Our output will be the city distance and the highway distance.

    cout << "City Distance: " << cityMiles << endl;
    cout << "Highway Distance: " << highwayMiles << endl;

I was going to put the entire program up but I think you should be able to figure out how to solve it from here!

/r/HomeworkHelp Thread