I'm making a program that tells the user how many galoons of fuel do you have to add to reach the destination but I don't know to do it because the values of the car tank, the mpg and the miles that the user wants to travel are all entered by the user.
This is the part that I need a few hints.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cout << "How many gallons your car have? ";
cin >> CarTank;
cout << "How many mile per hour your car can travel? ";
cin >> mpg;
cout << "How many miles you are planning to travel? ";
cin >> miles;
if (CarTank * mpg < miles) {
cout << "You are out of fuel! You need: " << Gallon << "more gallons" << endl;
}
You can drive CarTank*mpg miles with that. That is cars Range.
CarTank * mpg == Range
// mpg != 0. Lets divide both sides of the equation with mpg
<=>
CarTank * mpg / mpg == Range / mpg
// mpg/mpg==1. Simplify left side
<=>
CarTank == Range / mpg
Ok, I think that I understand but what happens if the reverse is true? The program is supposed to show the fuel remaining after the drive. It is more or less the same problem or I need to do something different this time? And thanks for helping me to understand the previous one!
1 2 3 4 5
if (CarTank * mpg > miles) {
cout << "You reached your destination! You have now: " << Gallon << " gallons remaining." << endl;
}