|
I'm trying to oompute miles driven and miles per gallon when the user inputs starting mileage, ending mileage, and gallons of gas used. I need to do this in a loop so they can enter info for up to 3 tanks. I can't get the miles driven to compute. I know the miles driven will equal the ending mileage minus the previous starting mileage but I can't get it to hold the new values in the loop.
Here's what I have so far:
do { cout << "Enter the gallons used (Enter -1 to End): "; cin >> gallonsUsed; totalGallonsUsed = (totalGallonsUsed + gallonsUsed);
cout << "Enter the ending mileage: "; cin >> endingMileage;
milesDriven = (endingMileage - milesDriven); cout << "Miles driven: " << milesDriven << endl;
totalMilesDriven = totalMilesDriven + milesDriven;
milesPerGallon = (milesDriven / gallonsUsed); cout << "The miles/gallon for this tank was: " << milesPerGallon;
overallMilesPerGallon = (totalMilesDriven / totalGallonsUsed);
|