Labels: mile gallon
Compute vehicle fuel-saving, compare by miles per gallon, allow repeated comparison
// Mile for gallon vehicle fuel saving # include <iostream> const double gallon = 0.264179; double milepergallon (double kilo, double mile); int main () {using namespace STD; double kilo [2], mile [2], milebygallon [2]; char ans; do {cout <"Enter the kilo and the mile of number first: \ n "; cin> kilo [0]> mile [0]; cout <"Enter the kilo and the mile of number second: \ n "; cin> kilo [1]> mile [1]; milebygallon [0] = milepergallon (kilo [0], mile [0]); milebygallon [1] = milepergallon (kilo [1], mile [1]); cout <"the first result is" <milebygallon [0] <"mile/gallon. \ n "; cout <" the second result is "<milebygallon [1] <" mile/gallon. \ n "; if (milebygallon [0]> milebygallon [1]) cout <" the first car fuel saving! "<Endl; else if (milebygallon [0] <milebygallon [1]) cout <" the second car fuel saving! "<Endl; else cout <" The Two cat are same saving oil! "<Endl; cout <" do you want again? "; CIN> ans;} while ('y' = ans | 'y' = ans); Return 0;} double milepergallon (double kilo, double mile) {double gallon; gallon = kilo * gallon; Return (mile/gallon );}
Result:
Enter the kilo and the mile of number first:1 0.264179Enter the kilo and the mile of number second:1 0.264179The first result is 1 mile/gallon.The second result is 1 mile/gallon.The two cat are same saving oil!Do you want again?yEnter the kilo and the mile of number first:1 1Enter the kilo and the mile of number second:10 2The first result is 3.78531 mile/gallon.The second result is 0.757062 mile/gallon.The first car fuel saving!Do you want again?yEnter the kilo and the mile of number first:1 1Enter the kilo and the mile of number second:2 2 The first result is 3.78531 mile/gallon.The second result is 3.78531 mile/gallon.The two cat are same saving oil!Do you want again?
Mile for gallon car fuel saving