Please can somebody help me with the line of codes of this question:write a C++ program which inputs litre consumption given in miles/gallon and which translates these figures into the litres/kilometre format which is more common in Europe.Use the following conversion factors: 1 mile=1.609km and 1 gallon= 3.785litres

Recommended Answers

All 3 Replies

The values you need are km per mi and gl per lt not lt per gl

lt/km = (mi/gl) * (km/mi) * (gl/lt)
lt/km = (given) * 1.609 * 0.264
lt/km = (given) * 0.425

Hope that helps.

Can get you started...

#include <iostream>

You're going to need a "main" function.
and a bit of mathematics.

Normally it's liters/100 kilometers but ignoring that detail.

If you have C in miles/gallon then you need to do 3 convertions

miles -> kilometers = times by 1.609
gallon -> liters = times by 3.785 (but note that gallons in underneath the line
distance/volume -> volume/distance = 1/x

so C miles/gallon === 1/(1.609C/3.785) = 3.785/1.609C liters/kilometer

So 30 mpg = 0.0784 liters/kilometer

Which as you can see is very small which is why liters/100 kilometer is more common

So 30 mpg = 7.8 liters/100 kilometer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.