Question: #include #include FuelGauge.h #include Odometer.h using namespace std; int main() { FuelGauge fuel(15); Odometer odm(0, &fuel); for(int i = 0; i < 15; i++) {
#include #include "FuelGauge.h" #include "Odometer.h" using namespace std;
int main() { FuelGauge fuel(15); Odometer odm(0, &fuel);
for(int i = 0; i < 15; i++) { fuel.incrementFuelTank(); }
while (fuel.getCurrentAmountOfFuel() > 0) { odm.incrementcurrentMileage(); cout << "Mileage: " << odm.getCurrentMileage() << endl; cout << "Fuel level:" << fuel.getCurrentAmountOfFuel() << " gallons" << endl; }
return 0; }
// FuelGauge.h using namespace std;
#ifndef FUELGAUGE_H #define FUELGAUGE_H
class FuelGauge { private: int currentAmountOfFuel;
public: FuelGauge(int gallons) { currentAmountOfFuel = gallons; } FuelGauge(); int getCurrentAmountOfFuel() { return currentAmountOfFuel; } void incrementFuelTank() { if(currentAmountOfFuel < 15) { currentAmountOfFuel++; } } void decrementFuelTank() { if(currentAmountOfFuel > 0) { currentAmountOfFuel--; } }
};
#endif
// Odometer.h #include "FuelGauge.h" using namespace std;
#ifndef ODOMETER_H #define ODOMTER_H
class Odometer { private: int currentMileage; FuelGauge *fuelG;
public: Odometer(int miles, FuelGauge *f) { currentMileage = miles; fuelG = f; }
int getCurrentMileage() { return currentMileage; } void incrementcurrentMileage() { if(currentMileage < 999999) { currentMileage++; } if(currentMileage == 999999) { currentMileage = 0; } } void decrementcurrentMileage() { if(currentMileage > 24) { currentMileage--; } } };
So, I have this code which is supposed to simulate a car odometer and fuel gauge and display the mileage and number of gallons but I just get an endless loop that says "Current amount of mileage is 15". I dont know what is happening, been looking at it for hours
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
