Thursday, 11 February 2016

Dealing with Data (C++ Primer Plus Sixth Edition Solution Manual) Question-7

Leave a Comment

Write a program that asks you to enter an automobile gasoline consumption figure in the European style (liters per 100 kilometers) and converts to the U.S. style of miles per gallon. Note that in addition to using different units of measurement, the U.S. approach (distance / fuel) is the inverse of the European approach (fuel / distance). Note that 100 kilometers is 62.14 miles, and 1 gallon is 3.875 liters.Thus, 19 mpg is about 12.4 l/100 km, and 27 mpg is about 8.7 l/100 km.


Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.


/*************C++ Programs And Projects************|

#include <iostream>

using namespace std;

int main() {
       const float milesPer100km = 62.14;
       const float litersPerGallon = 3.875;
       cout << "Enter automobile gasline consumption figure in the European stype (litters per 100 kilometers) :";
       double lp100km;
       cin >> lp100km;

       double mpg = 1 / (lp100km / litersPerGallon)  * milesPer100km;
       cout << lp100km
              << " litters per 100 kilometers = "
              << mpg
              << " miles per gallon"
              << endl;

C++ Programs And Projects

Related Articles:

C++ Primer Plus Sixth Edition Complete Solution Manual 

C++ Books Solution

If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: