Expected unqualified-id: Fuel usage program

The premise of this problem is to calculate the fuel used based on a user input fuel efficiency (in this case 45 mpg) and the miles driven (also input by user, in this case 100 miles). However, as I go to compile the code I get the error message "Expected unqualified-id" for the line void resetOdometer() {Odometer = 0;}

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
  #include <iostream>
using namespace std;

class Odometer
{
private:
    double miles, fuelEf;
public:
    Odometer(): fuelEf(0), miles(0){}
    void resetOdometer() {addOdometer = 0;}
    void setFE(double);
    void addOdometer(double);
    double returnFuel();
};

int main()
{
    // insert code here...
    // Two test trips
    Odometer trip1, trip2;
    trip1.resetOdometer();
    trip1.setFE(45);
    trip1.addOdometer(100);
    cout << "For your fuel-efficient small car:" << endl;
    cout << "After 100 miles, " << trip1.returnFuel() <<
    " gallons were used." << endl;
    trip1.addOdometer(50);
    cout << "After another 50 miles, " << trip1.returnFuel() <<
    " gallons were used." << endl;
    
    cout << endl;
    
    return 0;
}


What am I doing wrong?
Last edited on
Line 10: Odometer is a class name. You can't set a class name to 0. You can only set member variables to 0.

If you're trying to do aggregate initialization, the syntax is:
 
T object = {arg1, arg2, ...};	

Last edited on
Topic archived. No new replies allowed.