pseudo code

i'm reading c++ how to program by paul deitel. im having some problem with ex 4.13. Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several trips by recording miles driven and gallons used for each trip. Devel- op a C++ program that uses a while statement to input the miles driven and gallons used for each trip. The program should calculate and display the miles per gallon obtained for each trip and print the combined miles per gallon obtained for all tankfuls up to this point.
This is what i have . something wrong with my code. pls help!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
    int milesDriven = 0;
    int gallon = 0;
    double totalMiles;
    double totalGallon;

//get trip from user
    int trips = 0;
//accept the trip
//while trips > 0
    while (trips > 0 && milesDriven !=0) {
//get the miles driven
    cout << " Enter your miles driven: "<< milesDriven;
//get the gallon
    cout << " Enter gallon used: "<<gallon;
//add mile to total miles
        totalMiles += milesDriven;
//add total gallon
        totalGallon += gallon;
//trip-=1
        --trips;
    }//end loop
    
//milePerGallon = totalmiles/totalgallon
    double milePerGallon = totalMiles/totalGallon;
//display milePerGallon
    cout << milePerGallon << endl;
    // insert code here...

    return 0;
}
Your condition for the while statement on line#15 will be false, as 'trips' is equal to 0 and thus your code won't enter the while block and will simply go straight down to line#29
Thanks
Topic archived. No new replies allowed.