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.
#include <iostream>
usingnamespace 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
constdouble 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
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