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

Hello. The code below is written so that it determines the miles-per-gallon base

ID: 3880407 • Letter: H

Question

Hello. The code below is written so that it determines the miles-per-gallon based on the number of miles driven and the number of gallons of gas in the tank.

Please help in commenting the code and identifying the variables, expressions, and data types in this code:

#include <iostream>
using namespace std;

int main()

{
int miles;
int gallons;
float mpg;

cout << "Enter miles: ";
cin >> miles;
cout << "Enter gallons: ";
cin >> gallons;

mpg = (float)miles / gallons;
cout << "Miles per gallon: " << mpg << endl;
return 0;
}

Explanation / Answer

/* Import iostream header file*/

#include <iostream>
using namespace std;

int main()

{

/*int, float are data types*/

/*miles, gallons, mpg are variables to hold the input and output values*/
int miles;
int gallons;
float mpg;

/*Promt user to enter number of miles*/

cout << "Enter miles: ";

/* Read user input into miles variable*/
cin >> miles;

/*Promt user to enter number of gallons*/
cout << "Enter gallons: ";

/* Read user input into gallons variable*/
cin >> gallons;

/*Calculate the miles-per-gallon value using below expression and store the result in variable mpg*/

mpg = (float)miles / gallons;

/*Display the calculated mile-per-gallon value to the user*/
cout << "Miles per gallon: " << mpg << endl;
return 0;
}