Avatar of boula
boula
 asked on

Need help getting this program running.

Define a class called Odometer that will be used to track fuel and mileage for an automotive vehicle.  The class should have member variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon.  Include a mutator function to reset the odometer to zero miles, a mutator function to set the fuel efficiency, a mutator function that accepts miles driven for a trip and adds it to the odometers total, and an accessor method that returns the number of gallons of gasoline that the vehicle has consumed since the odometer was last reset.  

Getting lots of errors and I cant figure it out...
#include <iostream>
using namespace std;
 
class odometer
{
      int gallons_consumed;
private:
         int miles_tracker;
         double fuel_eff; 
         int getmiles
public:
        odometer();
        void reset();
        void compute_fuel();
        void input_miles(int getmiles);
        void odometer::set_fuel_eff(double fuel_eff);
        double odometer::get_num_gallons();
};
 
odometer::odometer()
{
                    miles_tracker = 0;
                    fuel_eff = 0;
}
void odometer::reset()
{   
                      miles_tracker = 0;
}
void odometer::compute_fuel()
{
     fuel_eff = (miles_tracker/gallons_consumed);
}
void odometer::input_miles(int miles_driven)
{
     miles_tracker = miles_tracker + miles_driven;
}
void odometer::set_fuel_eff(double Fuel_eff)
{
     fuel_eff = Fuel_eff;
}
double odometer::get_num_gallons()
{
       return miles_tracker/fuel_eff;
}
 
int main()
{
    odometer simulator;
    int miles_driven
    int fueleff;
    
        cout<<"Enter the amount of miles driven :"<<endl;
        cin>> miles_driven;
              simulator.reset();
              simulator.input_miles(miles_driven);
        count << "Enter feul efficiency : "<<endl;
        cin >> fueleff;
               simulator.set_fuel_eff(fueleff);
        cout<<"Number of miles:"<<simulator.getmiles()<<end1
        cout<<"Number of Gallons consumed: "<<simulator.get_num_gallons()<<endl;
    system("pause");
   
}

Open in new window

C++C#

Avatar of undefined
Last Comment
itsmeandnobodyelse

8/22/2022 - Mon
anneb

I assume you are building this odometer class for learning purposes?

Instead of solving the problem for you, I'll try to give some hints.

1. Normally you get lots of errors in a C++ compiler, even if you made one typing error. Start by looking closely at the first error message

2. If the error message makes sense, solve the problem and recompile.

3. If you are getting error message that are not clear to you, please post the error message.
boula

ASKER
Yeah i am just not seeing it. IM not sure, am I calling the functions wrong in my main? maybe it is because my brain is mush I been working on this all day.
here is a list of errors I cant figure it out.
11: error: expected `;' before "public"
:21: error: definition of implicitly-declared `odometer::odometer()'
:21: error: declaration of `odometer::odometer()' throws different exceptions
:5: error: than previous declaration `odometer::odometer() throw ()'
 In function `int main()':

26: error: `void odometer::reset()' is private
54: error: within this context
34: error: `void odometer::input_miles(int)' is private
55: error: within this context
56: error: invalid operands of types `<unknown type>' and `const char[25]' to binary `operator<<'
:38: error: `void odometer::set_fuel_eff(double)' is private
58: error: within this context
59: error: 'class odometer' has no member named 'getmiles'
60: error: `end1' undeclared (first use this function)
60: error: (Each undeclared identifier is reported only once for each function it appears in.)
:60: error: expected `;' before "cout"

Execution terminated


Gonna keep messing with it, thanks for your help.
boula

ASKER
well i took care of 8 errors. these are the errors that I am dealing with now.

: In function `int main()':
:58: error: invalid operands of types `<unknown type>' and `const char[25]' to binary `operator<<'

10: error: `int odometer::getmiles' is private
61: error: within this context
:61: error: `simulator.odometer::getmiles' cannot be used as a function
:62: error: `end1' undeclared (first use this function)
62: error: (Each undeclared identifier is reported only once for each function it appears in.)
:62: error: expected `;' before "cout"

any help would is appreciated.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
boula

ASKER
Ok, I am down to just 2 errors. I hope someone can help me out because i am not sure what to do to fix them.

59  invalid operands of types `<unknown type>' and `const char[25]' to binary `operator<<'
62 `simulator.odometer::getmiles' cannot be used as a function
#include <iostream>
using namespace std;
 
class odometer
{
     int gallons_consumed;
private:
         int miles_tracker;
         double fuel_eff; 
        
        
public:
        odometer();
        void reset();
        void compute_fuel();
        void input_miles(int getmiles);
        void odometer::set_fuel_eff(double fuel_eff);
        double odometer::get_num_gallons();
        int getmiles;
        
};
 
odometer::odometer()
{
                    miles_tracker = 0;
                    fuel_eff = 0;
}
void odometer::reset()
{   
                      miles_tracker = 0;
}
void odometer::compute_fuel()
{
     fuel_eff = (miles_tracker/gallons_consumed);
}
void odometer::input_miles(int miles_driven)
{
     miles_tracker = miles_tracker + miles_driven;
}
void odometer::set_fuel_eff(double Fuel_eff)
{
     fuel_eff = Fuel_eff;
}
double odometer::get_num_gallons()
{
       return miles_tracker/fuel_eff;
}
 
int main()
{
    odometer simulator;
    int miles_driven;
    int fueleff;
    
        cout<<"Enter the amount of miles driven :"<<endl;
        cin>> miles_driven;
              simulator.reset();
              simulator.input_miles(miles_driven);
        count << "Enter fuel efficiency : "<< endl;
        cin >> fueleff;
               simulator.set_fuel_eff(fueleff);
        cout<<"Number of miles:"<<simulator.getmiles()<< endl;
        cout << "Number of Gallons consumed: "<<simulator.get_num_gallons()<<endl;
    system("pause");
   
}

Open in new window

ASKER CERTIFIED SOLUTION
anneb

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
itsmeandnobodyelse

>>>> cout<<"Number of miles:"<<simulator.getmiles()<< endl;
As far as I see getmiles is an int and not a function. Hence you would need to remove the () after getmiles.

BTW, getmiles is a poor name for a data member and the error was only caused by the poor naming.
itsmeandnobodyelse

>>>> line 61: getmiles is a member variable of odometer, not a member function.

Sorry, anneb. Didn't read your last comment thoroughly before posting.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
boula

ASKER
That did it. Thanks for the help!
itsmeandnobodyelse

You shouldn't have accepted my comment but that of anneb #25492744 cause that comment already was the solution.