Hello I'm trying to write a program that computes miles per gallon by,writing a function that computes miles per gallon a sample output of this goes like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
**** Welcome to MPG converter ****
How many liters did your car consume: 5.0
How many miles did your car travel: 21.0
==> Your car delivered 15.90 miles per gallon (MPG).
Do you want to continue (y/n)? y
How many liters did your car consume: 5.0
How many miles did your car travel: 26.3
==> Your car delivered 19.91 miles per gallon (MPG).
Do you want to continue (y/n)? n
**** Thank you !!! ****
now the code that I have at the moment is like this
#include <iostream>
usingnamespace std;
constdouble gpl = 0.264179; //gallon per liter.
//prototype
double computeNumMPG();
int main()
{
cout << "**** Welcome to MPG converter ****\n\n";
double liters;
double miles;
double gallons;
cout << "How many miles did your car travel: ";
cin >> miles;
double mpg;
gallons = copmuteNumMPG();
mpg = miles / gallons;
cout << "==> Your car delivered " << mpg << " miles per gallon (MPG).\n\n";
//system"pause";
return 0;
}
int computeNumMPG()
{
double liters;
double gallons;
cout << "How many liters did your car consume: ";
cin >> liters;
gallons = gpl * liters;
return gallons;
}
i am aware that there is an error with the code, that is the problem i have, I'm not quite sure what I'm doing wrong or what I'm doing wrong. Thank you if anyone wants or can help me I would appreciate it.