This is my first time using overloading functions and im stuff on how i would set up what will be returned as well as making it so the program out puts which car has the best MPG.
This is suppose to convert the liters input by the user into gallons and gather the distance as well to find the MPG. The program needs to allow the user to run it as many times as they like. After all this is gathered then it tells the user which car has the best MPG.
#include <iostream>
usingnamespace std;
double mpg(double liters, int miles);
//Returns the mpg of car 1
double mpg(double liters, double miles);
//Returns the mpg of car 2
constdouble GALLONS_PER_LITER = 0.264179; //conversion of how many gallons are in a liters, global
char ans;
int main() {
double liters, mpg;
int miles;
do {
cout << " How many liters of gas are in your tank: ";// asks user for liters in tank
cin >> liters;
cout << " How many miles did you travel: "; // asks user for distance traveled
cin >> miles;
mpg = miles / (liters * GALLONS_PER_LITER); // function to find MPG
cout << " Your car's MPG is " << mpg << ".\n"; // outputing the users MPG
cout << " Would you like to run the program again?";//Allowing user the option to run again
cin >> ans;
}while (ans == 'y' || ans == 'Y');
system("pause");
return 0;
}
double mpg(double liters, double miles) {
double rate, mpg;
cout << " How many liters of has are in your tank: ";
cin >> liters;
cout << " How many miles did you travel: ";
cin >> miles;
mpg = miles / (liters * GALLONS_PER_LITER);
}
This isnt overloading operators... Last time I remember, overloading functions are like: operator== operator<< inside of classes.
What you need to do is just google the conversion ratio of liter to gallon, and you are also not defining the variable ans in your code.