A car with a 18 gallon gas tank can average 21.5 miles per gallon when driven in
ID: 3529343 • Letter: A
Question
A car with a 18 gallon gas tank can average 21.5 miles per gallon when driven in the stop and go traffic of the cityand 26.8 miles per gallon when driven on the highway. Write a program that prompts the user for two inputs : how many miles they will drive in the city and how many miles they plan on driving on the highway. The program should output the number of gallons of gas which will be required and the number of times the driver will have to buy fuel, assuming each refueling will entirely fill the tank.Explanation / Answer
#include<iostream>
using namespace std;
int main(){
const int TANK =18;
const double CITYRATE=21.5;
const double HIGHWAYRATE=26.8;
double city, highway; //number of miles to drive
double cityGallon,highwayGallon; //number of gallons needed
cout<<"Enter miles to drive in city: ";
cin>>city;
cout<<"Enter miles to drive on highway: ";
cin>>highway;
cityGallon= city/CITYRATE;
highwayGallon=highway/HIGHWAYRATE;
cout<<"You would use "<<cityGallon<<" gallons in the city, which requires "<<(int)(cityGallon/TANK)<<" re-fuels."<<endl;
cout<<"You would use "<<highwayGallon<<" gallons in the highway ohich requires "<<(int)(highwayGallon/TANK)<<" re-fuels."<<endl;
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.