Write a program that calculates a car’s gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold and the number of miles it can be driven on a full tank. It should then calculate and display the number of miles per gallon the car gets.

 

Solution:

 

include <iostream> using namespace std;

int main() { double numOfGallons, numOfMiles; cout<<“Enter the number of gallons of gas the car can hold: “;   //Reads total gallons. cin>>numOfGallons; cout<<“Enter the number of miles it can be driven on a full tank: “;   //Rads total miles. cin>>numOfMiles; cout<<“The mileage of the car is: “<<numOfMiles/numOfGallons<<” miles per gallon.”<<endl;   //Displays mileage. }