May 7, 2015 at 6:15am UTC
Yes, I have a problem with this Car Simulation project that keeps not compiling. keeps on saying expression not used Fuel::Fuel
[]
#include <iostream>
#include <string>
#include <cstdlib>
#include "FuelGauge.h"
#include "Odometer.h"
int main()
{
FuelGauge fuelG(15)
Odometer Odometer(int miles)
while(fuelG.getCurrentAmountofFuel() > 0)
{
odm.incrementcurrentMileage();
std::cout << "The Current Amount of Miles is: "<< fuelG.getCurrentAmountofFuel() << std::endl;
if( odm.getCurrentMileage() % 24 == 0)
{
std::cout << "The current amount of fuel is: "<< fuelG.getCurrentAmountofFuel() << std::endl;
}
}
getchar()
return 0;
}
#include "fuelgauge.h"
FuelGauge::FuelGauge()
{
}
FuelGauge::~FuelGauge(int gallons)
{
[#ifndef FUELGUAGE_H
#define FUELGUAGE_H
#include <iostream>
#include <cstdlib>
#include <string>
class FuelGauge
{
private:
int currentAmountOfFuel;
public:
FuelGauge(int gallons)
{
currentAmountOfFuel = gallons;
}
FuelGauge();
int getCurrentAmountOfFuel()
{
return currentAmountOfFuel;
}
void incrementFuelTank()
{
if (currentAmountOfFuel < 15)
std::cout << currentAmountOfFuel++;
}
void decrementFuelTank()
{
if(currentAmountOfFuel > 0)
std::cout << currentAmountOfFuel--;
}
};
#endif]
#include "odometer.h"
Odometer::Odometer()
{
}
Odometer::~Odometer()
{
}
#ifndef ODOMETER_H
#define ODOMETER_H
#include <iostream>
#include <string>
#include "FuelGauge.h"
class Odometer
{
private:
int currentMileage;
//FuelGauge fuelG;
public:
Odometer(int miles)
{
currentMileage = miles;
//fuelG = f;
}
int getcurrentMileage()
{
return currentMileage;
}
void incrementcurrentMileage()
{
if(currentMileage < 999,999)
currentMileage++;
else
currentMileage = 0;
std::cout << "Now the current mileage is " << currentMileage << std::endl;
std::cout << "I will increment miles again.\n\n";
if(currentMileage == 999,999 )
currentMileage = 0;
}
void decrementcurrentMileage()
{
if(currentMileage > 24 )
currentMileage--;
std::cout << "Now the current mileage is " << currentMileage << std::endl;
std::cout << "I will decrement miles again.\n\n";
}
};
#endif
how you put code in code tags
Last edited on May 7, 2015 at 12:19pm UTC
May 7, 2015 at 10:14am UTC
Please edit your post and put your code in code tags - makes it much easier for us to help you.
May 7, 2015 at 10:22am UTC
Anyway, as far as I can see there are quite a few problems.
In your main, you create a array of objects called fuelG:
FuelGauge fuelG(15);
However, you are not accessing each individual object in your while statement:
while (fuelG.getCurrentAmountofFuel() > 0)
You also reference fuelG.getCurrentAmountofFuel()
without telling it what object.
Because you have created an array of objects you then need to treat it like a array, for example..
fuelG[0].getCurrentAmountofFuel()
, 0 being the first object, 1 being the second and so on.
There may be more errors but those stand out to me.
May 7, 2015 at 3:44pm UTC
[Yes, I have a problem with this Car Simulation project that keeps not compiling. keeps on saying expression not used Fuel::Fuel
[]
#include <iostream>
#include <string>
#include <cstdlib>
#include "FuelGauge.h"
#include "Odometer.h"
int main()
{
FuelGauge fuelG(15)
Odometer Odometer(int miles)
while(fuelG.getCurrentAmountofFuel() > 0)
{
odm.incrementcurrentMileage();
std::cout << "The Current Amount of Miles is: "<< fuelG.getCurrentAmountofFuel() << std::endl;
if( odm.getCurrentMileage() % 24 == 0)
{
std::cout << "The current amount of fuel is: "<< fuelG.getCurrentAmountofFuel() << std::endl;
}
}
getchar()
return 0;
}
#include "fuelgauge.h"
FuelGauge::FuelGauge()
{
}
FuelGauge::~FuelGauge(int gallons)
{
[#ifndef FUELGUAGE_H
#define FUELGUAGE_H
#include <iostream>
#include <cstdlib>
#include <string>
class FuelGauge
{
private:
int currentAmountOfFuel;
public:
FuelGauge(int gallons)
{
currentAmountOfFuel = gallons;
}
FuelGauge();
int getCurrentAmountOfFuel()
{
return currentAmountOfFuel;
}
void incrementFuelTank()
{
if (currentAmountOfFuel < 15)
std::cout << currentAmountOfFuel++;
}
void decrementFuelTank()
{
if(currentAmountOfFuel > 0)
std::cout << currentAmountOfFuel--;
}
};
#endif]
#include "odometer.h"
Odometer::Odometer()
{
}
Odometer::~Odometer()
{
}
#ifndef ODOMETER_H
#define ODOMETER_H
#include <iostream>
#include <string>
#include "FuelGauge.h"
class Odometer
{
private:
int currentMileage;
//FuelGauge fuelG;
public:
Odometer(int miles)
{
currentMileage = miles;
//fuelG = f;
}
int getcurrentMileage()
{
return currentMileage;
}
void incrementcurrentMileage()
{
if(currentMileage < 999,999)
currentMileage++;
else
currentMileage = 0;
std::cout << "Now the current mileage is " << currentMileage << std::endl;
std::cout << "I will increment miles again.\n\n";
if(currentMileage == 999,999 )
currentMileage = 0;
}
void decrementcurrentMileage()
{
if(currentMileage > 24 )
currentMileage--;
std::cout << "Now the current mileage is " << currentMileage << std::endl;
std::cout << "I will decrement miles again.\n\n";
}
};
#endifcode][/code]
May 7, 2015 at 4:03pm UTC
Yes, and you haven't read my last post either. Put your code in code tags, and look at what I wrote earlier.