Please help! I don't understand why I am getting this error: function does not take 0 arguments.

The program is suppose to calculate how much fuel is left in the tank after you drive a certain amount of miles.

Can someone please help explain why I am getting this error?

Thanks,

Dennis

#include <iostream>
#include <cmath>

using namespace std;

class Car
{
public:
	Car();
	void read();
	void get_gas(double fuel_level);
	void print() const;
private:
	double fuel_efficiency;
	double initial_fuel;
	double fuel_level;
	double distance;
};
Car::Car()
{
	fuel_efficiency = 0;
	fuel_level = 0;
	distance = 0;
}
void Car::read()
{
	cout << " \n *** Car Class Testing Program *** \n ";
	cout << " Enter fuel efficiency in miles / per gallon: ";
        cin >> fuel_efficiency;  
        cout << " How many gallons of fuel did you start with?: ";
        cin >> initial_fuel;  
        cout << " How many miles will you be driving?: ";
        cin >> distance;
}
void Car::get_gas(double fuel_level)
{
	fuel_level = distance/fuel_efficiency - initial_fuel;
}
void Car::print() const
{
	cout << "After the drive you will have ";
	cout << fuel_level << " gallons of fuel left in the car";
}
int main()
{
	Car my_car;
	my_car.read();
	my_car.get_gas();
	my_car.print();

	return 0;
}

Recommended Answers

All 5 Replies

Well the member function 'get_gas' requires a double..

void Car::get_gas(double fuel_level)

So, can you tell me how to fix it. I've been spending hours looking at this and changing things around with no success. I need to use the input from the read():: portion not actual numbers.

Thanks in advance!

void Car::get_gas()

While I'm here, take a close look at how you are calculating the fuel_level.

What exactly is Car::get_gas() intended to do? It looks like you have it set up to do 2 different jobs, but you don't correctly implement/complete either job...

Is it intended to add gas to the vehicle ( void Car::get_gas(double) ), or is it intended to calculate fuel consumption ( double Car::get_gas(void) )? Notice the difference in the recommended prototypes.

Given the behavior of your Car::read() function and the calculation you perform within the Car::get_gas() function, it looks like it's intended to calculate consumption. Assuming that's true, Car::get_gas() will require a different prototype than what you have.

Thanks everyone! I changed a few things and it works properly now. I appreciate the help!

Dennis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.