[go: up one dir, main page]

0% found this document useful (0 votes)
8 views1 page

MPG

Uploaded by

meihuunkoosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

MPG

Uploaded by

meihuunkoosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//program for problem on page 179 of cpp deitel

//page is not pdf page

#include <iostream>
using namespace std;

int main()
{
int miles_driven;
int gallons_used;
int total_md;
int total_gU;
double current_mpg;
double total_mpg;

cout << "Enter miles driven (-1 to quit): ";


cin >>miles_driven;

total_md =0;
total_gU = 0;

while(miles_driven != -1)
{

cout << "Enter gallons used: ";


cin >>gallons_used;

total_md = miles_driven +total_md;


total_gU = gallons_used + total_gU;
current_mpg = static_cast<double>(miles_driven)/gallons_used;
total_mpg = static_cast<double>(total_md)/total_gU;

cout << "MPG this trip: "<<current_mpg<<endl;


cout << "Total MPG: "<<total_mpg<<endl;

cout << "\nEnter miles driven (-1 to quit): ";


cin >>miles_driven;
}

You might also like