81.9k views
5 votes
A car holds 16 gallons of gasoline and can travel 312 miles before refueling. Write aC++ program that calculates the number of miles per gallon the car gets. Display the result on the screen.

User Dokkaebi
by
7.6k points

1 Answer

1 vote

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables Declaration and initialization

int no_gallon=16;

int dis=312;

// find the miles per gallon

double mile_gallon=dis/double(no_gallon);

// print the results

cout<<"number of gallons: "<<no_gallon<<endl;

cout<<"distance travel before refueling: "<<dis<<endl;

cout<<"miles per gallon is: "<<mile_gallon<<endl;

return 0;

}

Step-by-step explanation:

Declare and initialize the number of gallon and distance travel without refueling. Calculate the miles per gallon by dividing distance with number of gallons.Then print the results.

Output:

number of gallons: 16

distance travel before refueling: 312

miles per gallon is: 19.5

User Josh Larson
by
7.6k points