-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (57 loc) · 2.35 KB
/
main.cpp
File metadata and controls
77 lines (57 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
using namespace std;
double caclUnitPrice(double roundPrice, int diameter );
double caclUnitPrice(double squarePrice, int width, int length);
int main() {
// declare vars
int diameter, width, length;
double roundPrice, squarePrice, roundUnitPrice, squareUnitPrice;
// prompt and capture values
cout << "Welcome to Compare A Pizza" << endl;
cout << "---------------------------------------------"<< endl;
cout << endl;
cout << "Enter the diameter of a round Pizza in cm" << endl;
cin >> diameter;
cout << "Enter the price of a round Pizza in $" << endl;
cin >> roundPrice;
cout << "Enter the width of a square/rectangular Pizza in cm" << endl;
cin >> width;
cout << "Enter the length of a square/rectangular Pizza in cm" << endl;
cin >> length;
cout << "Enter the price of a round Pizza in $" << endl;
cin >> squarePrice;
//set precision etc for cout doubles
cout.setf(ios::fixed);
cout.precision(2);
// calculate the price per cm2 for round pizza
roundUnitPrice = caclUnitPrice(roundPrice, diameter);
cout << "The round pizza unit price is " << roundUnitPrice << "/cm2" << endl;
cout << "---------------------------------------------"<< endl;
cout << endl;
// calculate the price per cm2 for square pizza
squareUnitPrice = caclUnitPrice(squarePrice, width, length);
cout << "The square pizza unit price is " << squareUnitPrice << "/cm2" << endl;
cout << "---------------------------------------------"<< endl;
cout << endl;
// output the one with the lower price per cm2
if(roundUnitPrice < squareUnitPrice){
cout << "The round pizza is the better deal" << endl;
} else {
cout << "The square/rectangle pizza is the better deal" << endl;
}
cout << "---------------------------------------------"<< endl;
cout << "più pomodoro per favore!!!" << endl;
return 0;
}
double caclUnitPrice(double roundPriceP, int diameterP ){
double const PI = 3.14159;
double radius = diameterP/2.0;
double area = PI * radius * radius;
cout << "Round Pizza total cm2 = " << area << endl;
return roundPriceP/area;
}
double caclUnitPrice(double squarePriceP, int widthP, int lengthP ){
double area = widthP * lengthP;
cout << "Square Pizza total cm2 = " << area << endl;
return squarePriceP/area;
}