think about the flow of your program.
-Ask two questions.
-store the answers.
-Use the answers in a calculation.
-display the results.
The value of your variable can be changed as many times as you want throughout your program, so don't get confused with thinking that you have to have the final result at the time of declaration.
Also, as stated, in C++ you do not have to declare your variables at the top of your code.
Code:
#include <iostream>
using namespace std;
int main()
{
const double GALLONS_PER_LITER = 0.264179; //give a meaningful name to conversion constant
int liters = 0; //will be set by cin before we use in calculation, but
double distance = 0.0; //it's nice to get in the habit of initializing variables
double mpg = 0.0; //could (should) wait to declare this until closer to where we need it
do
{
cout << "Please input how many liters of gasoline is in your vehicle: ";
cin >> liters;
cout << "Please input the distance in miles you traveled in your vehicle: ";
cin >> distance;
//We've got our user input... let's do our calculation.
mpg = distance / (liters * GALLONS_PER_LITER);
// OR
//we could just as well declare mpg here and omit mpg lines above
//double mpg = distance / (liters * GALLONS_PER_LITER);
//display results
cout << "Your vehicle's MPG is: " << mpg << endl;
}while(liters >-1);
return 0;
}