pizza2.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 52 行

CPP
52
字号
#include <iostream>using namespace std;// find the price per square inch of pizza// to compare large and small sizes for the best value//// Owen Astrachan// March 29, 1999//double Cost(double radius, double price)// postcondition: returns the price per sq. inch{    return price/(3.14159*radius*radius);}int main(){    double smallRadius, largeRadius;    double smallPrice, largePrice;    double smallCost,largeCost;    // input phase of computation        cout << "enter radius and price of small pizza ";    cin >> smallRadius >> smallPrice;    cout << "enter radius and price of large pizza ";    cin >> largeRadius >> largePrice;    // process phase of computation        smallCost = Cost(smallRadius,smallPrice);    largeCost = Cost(largeRadius,largePrice);    // output phase of computation        cout << "cost of small pizza = " << smallCost << " per sq.inch" << endl;    cout << "cost of large pizza = " << largeCost << " per sq.inch" << endl;    if (smallCost < largeCost)    {   cout << "SMALL is the best value " << endl;    }    else    {   cout << "LARGE is the best value " << endl;    }        return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?