pizza program

PHOTO EMBED

Wed Sep 28 2022 04:19:09 GMT+0000 (Coordinated Universal Time)

Saved by @Kyle #c++

#include <iostream>
#include <cmath>
using namespace std;

double unitprice(int diameter, double price) {
    const double PI = 3.14159;
    double radius, area;
    
    radius = diameter / static_cast <double> (2);
    area = PI * radius * radius;
    return (price/area);
}

int main() {
    
    int diameter_small, diameter_large;
    double price_small, unitprice_small,
        price_large, unitprice_large;
    
    cout << "Please enter the diameter of the small pizza: ";
    cin >> diameter_small;
    cout << "Please enter the price of the small piza: $";
    cin >> price_small;
    cout << "Please enter the diameter of the large pizza: ";
    cin >> diameter_large;
    cout << "Please enter the price of the large piza: $";
    cin >> price_large;
    
    unitprice_small = unitprice(diameter_small, price_small);
    unitprice_large = unitprice(diameter_large, price_large);
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    
    cout << "-------------------------------------\n"
        << "I see... \n";
    
    if (unitprice_large < unitprice_small) {
        cout << "Seems like the larger pizza is the better option,\n";
        cout << "I suggest you buy it.\n";
    }
    
    else 
    {
        cout << "Seems like the smaller one is the better option,\n";
        cout << "I suggest you buy it.\n";
    }
    
    return 0;
}
content_copyCOPY