Cake problem

PHOTO EMBED

Sat Oct 01 2022 13:35:39 GMT+0000 (UTC)

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);
}

double unitprice(int length, int width, double price) {
    double area = length * width;
    return (price/area);
}

int main() {
    
    int diameter, length, width;
    double price_round, unitprice_round,
        price_rectangular, unitprice_rectangular;
    
    cout << "Please enter the diameter of the round cake: ";
    cin >> diameter;
    cout << "Please enter the price of the round piza: $";
    cin >> price_round;
    cout << "Please enter the length and width of the rectangular\n"
        << "cake in inches: ";
    cin >> length >> width;
    cout << "Please enter the price of the rectangular cake: $";
    cin >> price_rectangular;
    
    unitprice_rectangular = unitprice(length, width, price_rectangular);
    unitprice_round = unitprice(diameter, price_round);
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    
    cout << "-------------------------------------\n"
        << "I see... \n";
    
    if (unitprice_round < unitprice_rectangular) {
        cout << "Seems like the round cake is the better option,\n";
        cout << "I suggest you buy it.\n";
    }
    
    else 
    {
        cout << "Seems like the rectangular one is the better option,\n";
        cout << "I suggest you buy it.\n";
    }
    
    return 0;
}
content_copyCOPY