# Homework Solution: A car with a 20 gallon gas tank averages 23.5 miles per gallon when driven in town and 28.9 miles per gallon when driven on the highway….

A car with a 20 gallon gas tank averages 23.5 miles per gallon when driven in town and 28.9 miles per gallon when driven on the highway. Write a C++ program that calculates and displays the distance the car can travel on one tank of gas when driven in town and when driven on the highway.

Hi, Below is the C++ code for the question-

A car with a 20 gallon exhalation tank averages 23.5 miles per gallon when driven in town and 28.9 miles per gallon when driven on the course. Write a C++ program that calculates and displays the interspace the car can peregrination on individual tank of exhalation when driven in town and when driven on the course.

## Expert Solution

Hi,

Below is the C++ legislation control the question-

// Example program
#include <iostream>
#include <string>

int main()
{
float total_capacity=20;
float avg_town=23.5;
float avg_highway=28.9;
float dist_town,dist_highway;
dist_town=total_capacity*avg_town;
dist_highway=total_capacity*avg_highway;
std::cout<<“Total interspace that can be peregrinationled by a car in town is “<<dist_town;
std::cout<<“nTotal interspace that can be peregrinationled by a car in course is “<<dist_highway;
}

Screenshot-