Km to miles conversion

I have a task of making conversion of Kilometer into miles, which I did successfully in below here. now I must include to display the amount of fuel consumed. assuming fuel consumption of the car is 2 liters per mile. I've no idea how to start doing that, any hint you provide would be very much appreciated.

I should mention that I just started learning c++ last month. please do provide a laymen term hint for me.

Thank you,

ywyak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
using namespace std;
int main()
{
	int liters;
	double kms, miles, km_per_mile;
	km_per_mile = 0.621;
	

	cout << "What is the distance in Kilometer?" << endl;
	cin >> kms;


    miles = kms * km_per_mile;
	cout << "The distance in Miles is: " << miles << endl;
	

	return 0;
}
//1 Km= 0.621 Mph
// 2 Liter per miles fuel consumption
closed account (E3h7X9L8)
1
2
3
4
const double litersPerMile = 2; //constant variable that cant be changed recommend using those
                                          // for variables that you dont need to change in program execution
double totalLiters = miles * litersPerMile; //calculate liters consumption
cout << totalLiters; // display liter consumption 
Last edited on
The name "km_per_mile" is incorrect, since the variable actually contains the miles per kilometer, and it's also used as if it contains miles per kilometer.

km * mile/km =
km * mile * 1/km =
km * 1/km * mile =
km/km * mile =
mile
Topic archived. No new replies allowed.