Thursday, 11 February 2016

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

Leave a Comment
Questions:

Write a program that asks how many miles you have driven and how many gallons of gasoline you have used and then reports the miles per gallon your car has gotten. Or, if you prefer, the program can request distance in kilometers and petrol in liters and then report the result European style, in liters per 100 kilometers.
Explanation:

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.

Code:

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


#include <iostream>

using namespace std;

int main() {
       cout << "Enter the miles you have driven:";
       long miles;
       cin >> miles;

       cout << "Enter gallons of gasoline you have used:";
       long gas;
       cin >> gas;

       double milesPerGallon = miles / gas;

       cout << endl
              << milesPerGallon
              << " miles per gallon your car has gotten."
              << endl;
       return(0);
}



Output:
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