Mile for gallon car fuel saving

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.