Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must be in Visual studios Write a program named TankOfGas . The program will hav

ID: 3793110 • Letter: M

Question

Must be in Visual studios

Write a program named TankOfGas. The program will have the use input into a variable the number of gallons of gas in the gas tank, the miles per gallon in town and the miles per gallon on the highway (Optionally: you can also have the use input MPG for highway and town). Have the program calculate the number of miles traveled in town and on the highway. Display the result on the screen.

Default MPG could be 23.5 miles in town and 28.9 miles on the highway.

Calculate both miles in city and on the highway.

Hint: Distance = Number of Gallons X Average Miles per Gallon

Explanation / Answer


// C++ code TankOfGas
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


int main()
{

   double gas, mpgTown, mpgHighway;
   cout << "Enter number of gallons of gas in tank: ";
   cin >> gas;

   cout << "Enter miles per gallon in town: ";
   cin >> mpgTown;

   cout << "Enter miles per gallon on the highway: ";
   cin >> mpgHighway;

  
   cout << " Miles travelled in town: " << (gas*mpgTown) << endl;
   cout << "Miles travelled on highway: " << (gas*mpgHighway) << endl;

   return 0;
}

/*
output:

Enter number of gallons of gas in tank: 34
Enter miles per gallon in town: 23.5
Enter miles per gallon on the highway: 28.9

Miles travelled in town: 799
Miles travelled on highway: 982.6

*/