A liter is 0.264179 gallons. Write a program that will read in the number of lit
ID: 3644250 • Letter: A
Question
A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon.After doing this...
Modify your program so that it will take input data for two cars and output the number of miles per gallon delivered by each car. Your program will also announce which car has the best fuel efficiency (highest number of miles per gallon). Need help modifying this program.
#include <iostream>
using namespace std;
#define LPG (0.264179)
double MilesPerGallon(double milesf, double litersf)
{
return (milesf*LPG/litersf);
}
void main()
{
double fliters, fmiles, sliters, smiles, fmpg, smpg;
char continue;
do
{
cout<<"Enter miles traveled by first car"<<endl;
cin>>fmiles;
cout<<"Enter in liters gasoline consumed"<<endl;
cin>>fliters;
cout<<"Enter miles traveled by second car"<<endl;
cin>>smiles;
cout<<"Enter in liters gasoline consumed"<<endl;
cin>>sliters;
if (fliters == 0 || sliters == 0)
cout<<" Invalid input";
else
{
fmpg = MilesPerGallon (fmiles, fliters);
smpg = MilesPerGallon (smiles, sliters);
cout<<"Miles per gallon "<<fmpg<<endl;
cout<<"Miles per gallon "<<smpg<<endl;
}
if (fmpg == smpg)
{
cout<<"Both cars are best"<<endl;
}
else if (fmpg > smpg)
{cout<<"First car is best"<<endl;
else
cout<<"Second car is best"<<endl;
cout<<If you want to repeat calculations
press 'Y' or 'y'"<<endl;
cin>>Continue;
} while (Continue =='y' || Continue == 'Y');
system ("pause");
}
There are no errors, but nothing happens when I run it. I can't figure out what I am missing.I needd to be able to see the MPG and which car is the best.
Explanation / Answer
if (fmpg == smpg) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.