Q8) A car holds 12 gallons and can
travel 350 miles before refueling. Write a program that calculates the number
of miles per gallon the car gets. Display the result on the screen.
Hint: use the following formula to
calculate miles per gallon (MPG)
MPG = Miles Driven / Gallon of Gas
Used.
#include <iostream>
using namespace std;
int main()
{
int gallons,miles;
double mpg;
gallons=12;
miles=350;
mpg=miles/gallons;
cout<<"MPG = "<<mpg<<endl;
return 0;
}
using namespace std;
int main()
{
int gallons,miles;
double mpg;
gallons=12;
miles=350;
mpg=miles/gallons;
cout<<"MPG = "<<mpg<<endl;
return 0;
}
No comments:
Post a Comment