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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
#include <cstdarg>
#include <iomanip>
using namespace std;
const double PI = 3.14;
void useInput(int& , double&, int&, double&, int&, double&);
void calculate(int&, double&, double&, int&, double&, double&, int&, double&, double&);
void display(int, double, double, int, double, double, int, double, double, int);
int main(){
int sPizzaSize,
bestDeal=0, mPizzaSize, lPizzaSize;
double sPizzaPrice, sPricePerInch, mPizzaPrice, lPizzaPrice, mPricePerInch, lPricePerInch;
//First function call.
useInput(sPizzaSize, sPizzaPrice, mPizzaSize, mPizzaPrice, lPizzaSize, lPizzaPrice);
//Second function call.
calculate(sPizzaSize, sPizzaPrice, sPricePerInch, mPizzaSize, mPizzaPrice,mPricePerInch, lPizzaSize,
lPizzaPrice, lPricePerInch);
//Third function call.
display(sPizzaSize, sPizzaPrice, sPricePerInch, mPizzaSize, mPizzaPrice, mPricePerInch, lPizzaSize,
lPizzaPrice, lPricePerInch, bestDeal);
system("pause");
return 0;
}
//First function
void useInput(int& sPizzaS, double& sPizzaP, int&mPizzaS, double& mPizzaP, int& lPizzaS, double& lPizzaP)
{
cout <<" Small Pizza varies between 5 to 7 inches. Small pizza costs $12.90 " << endl;
cout << " Medium Pizza varies between 8 to 10 inches. Medium pizza costs $13.40 " << endl;
cout << " Large Pizza varies between 11 to 13 inches. Small pizza costs $27.90 " << endl;
do{
cout << "Enter diameter of a small pizza (in inches): " << endl;
cin >> sPizzaS;
break;
do{
cout << "Enter diameter of a medium pizza (in inches): " << endl;
cin >> mPizzaS;
break;
do{
cout << "Enter diameter of a large pizza (in inches): " << endl;
cin >> lPizzaS;
break;
} while (sPizzaS < 5 || sPizzaS > 7);
cout << "Enter the price of a small pizza: " << endl;
cin >> sPizzaP;
break;
} while (mPizzaS < 8 || mPizzaS > 10);
cout << "Enter the price of a medium pizza: " << endl;
cin >> mPizzaP;
break;
} while (lPizzaS < 11 || lPizzaS > 13);
cout << "Enter the price of a large pizza: " << endl;
cin >> lPizzaP;
}
//Second function
void calculate(int& sPizza, double& sPrice, double& sPricePerInch, int& mPizza, double& mPrice, double& mPricePerInch,
int& lPizza, double& lPrice, double& lPricePerInch){
double area = 0;
area = PI * (sPizza / 2);
sPricePerInch = sPrice / area;
area = PI * (mPizza / 2);
mPricePerInch = mPrice / area;
area = PI * (lPizza / 2);
lPricePerInch = lPrice / area;
int min = 0;
double minSquareInch = sPricePerInch;
if (sPricePerInch < minSquareInch)
minSquareInch = sPricePerInch;
min = sPricePerInch;
minSquareInch = mPricePerInch;
if (mPricePerInch < minSquareInch)
minSquareInch = mPricePerInch;
min = mPricePerInch;
minSquareInch = lPricePerInch;
if (lPricePerInch < minSquareInch)
minSquareInch = lPricePerInch;
min = lPricePerInch;
}
//Third function
void display(int sPizza, double sPrice, double sPricePerInch, int mPizza, double mPrice, double mPricePerInch,
int lPizza, double lPrice, double lPricePerInch, int bestDeal){
int smallPizza=0, medPizza=0, largePizza=0;
cout << fixed << setprecision(2);
cout << "Small pizza size = " << sPizza <<" " << "inches, price = $" << sPrice <<
"Per square Inch =$" << sPricePerInch << endl;
cout << "Medium pizza size = " << mPizza << " " << "inches, price = $" << mPrice <<
"Per square Inch =$" << mPricePerInch << endl;
cout << "Large pizza size = " << lPizza << " " << "inches, price = $" << lPrice <<
"Per square Inch =$" << lPricePerInch << endl;
if (bestDeal == smallPizza)
cout << " Dear customer, the small pizza is the better buy." << endl;
else if (bestDeal == medPizza)
cout << "Dear customer, the medioum Pizza is the better buy." << endl;
else
cout << "Dear customer, the large Pizza is the better buy" <<endl;
}
|