To calculate miles per gallon of a vehicle\'s fuel efficiency, one would divided
ID: 3783668 • Letter: T
Question
To calculate miles per gallon of a vehicle's fuel efficiency, one would divided the total number of miles driven by the number of. Also, 1 mile = 1.61 kilometers. 1 gallon = 3.79 liters Write the program to calculate the miles per the gallon using which the user inputs. Also, convert the result into the kilometers per liter. Include the necessary declarations and main method to run your class. What is the purpose/significance of the following statement: public static void main statement is: Also explain what each component is and its purpose in the what public: static:Explanation / Answer
#pragma argsused
#pragma hdrstop
#include<iomanip>
#include<iostream>
#include<conio>
using namespace std;
int main(int argc, char* argv[])
{
// declare the variables
double gallons; // read in the gallons
double miles; // read in the miles
double totalGallons; // calculate the total gallon input
double totalMiles; // calculate the total mile input
double total; // calculate the gallons/miles
double average; // calculate the average overall
double counter;
// initialization phase
total = 0; // initialise total
counter = 1; // initialise loop counter
cout << "Enter the gallons used( -1 to end): " << endl;
cin >> gallons;
cout << "Enter the miles driven: " << endl;
cin >> miles;
average = miles / gallons; // calculate the the current input
cout << average; // display average
// loop until sentinal value read from user
while ( gallons != -1 ) {
total = totalMiles + totalGallons;//add total of gallons to total of miles
counter = counter + 1; // increment the counter
// prompt for input and read the next gallons
cout << "Enter the gallons user( -1 to end): " << endl;
cout << "Enter the miles driven: " << endl;
}
// termination phase
// if user entered at least one gallon...
if ( counter != 0 ) {
// calculate average of all gallons over miles entered
average = static_cast< double >( total ) / counter;
// display overall average with six digits of precision
cout << "Overall average is " << setprecision( 6 )
<< fixed << average << endl;
}
else
cout << "No gallons or miles were entered" << endl;
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.