mpg换算工具

#include

int main()
{
    using namespace std;
    double num;
    const double KM = 100,MI = 62.14,GAL = 3.875;
    double mi_per_km,mi_per_gal,in,result;

    cout << "Enter the number of miles per gallon: ";
    cin >> num;
    mi_per_km = KM / MI;
    mi_per_gal = mi_per_km / GAL;
    in = num * mi_per_gal;
    result = KM / in;
    cout << num << " miles per gallon = " << result << " liter per 100km." << endl;
    return 0;
}

C++ primer plus pag:69

你可能感兴趣的:(C++)