Problem Set 2. How Many Pizzas?
Modify the program you wrote in Problem Set 1(Pizza Pi) so that it reports the number of pizzas you need to buy for a party if each person attending is expected to eat an average of four slices. The program should ask the user for the number of people who will be at the party and for the diameter of the pizzas to be ordered. It should then calculate and display the number of pizzas to purchase.The code for the above described problem is give below:
copy & enjoy!
#include "pch.h" // if you are not using Microsoft Visual Studio you can remove this line
#include <iostream> // input output library
#include <iomanip> // library for setting precision
using namespace std;
const double pi = 3.14159; // global veriable for pi and its value cannot be changed
const double slcArea = 14.125; // global variable for area of slices and this value cannot be changed
int main() // start of main function
{
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "|\t\t\t\t\t----Pizza Pi----\t\t\t\t\t |" << endl; // Program Title
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "| This program will ask for the number of people who will attend the party & diameter of Pizza |\n";
cout << "| and then it will tell you how many pizzas you should buy for the party. |\n";
cout << "--------------------------------------------------------------------------------------------------" << endl;
double dimtr, // Here "dimtr" stands for diameter of the pizza
nSlc, // Here "nSlc" stands for number of slices of pizza
area, // Here "area" stands for the area of the pizza
nPple, // Here "nPple" stands for the number of people
nPiz, // Here "nPiz" stands for the number of pizzas
radius;
cout << "| How many people are comming to your party?\t\t\t\t\t\t |" << endl;
cout << "| ";
cin >> nPple;
cout << "| Write the dimeter in inches of pizza you want to buy. \t\t\t\t\t |" << endl;
cout << "| ";
cin >> dimtr; // Input from the user for the diameter of the Pizza
radius = dimtr / 2; // converts diameter of pizza into radius
area = pi * pow(radius, 2); // finds the area of the piza as Area = πr2
nSlc = area / slcArea; // finds the number of slices can be takken from one pizza
nPiz = (nPple * 4) / nSlc;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "| \t\t\tThe pizza of diameter " << dimtr << " will have about " << setprecision(1) << fixed << nSlc << " slices\t\t\t |" << endl;
cout << "|\t\t\t If each person eats 4 slices in the party\t\t\t\t |" << endl;
cout << "| \t\tthe you should buy about " << nPiz << " pizzas to fullfil the need of the party\t\t |" << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << endl;
cout << " \t\t\t\t-----------------------------" << endl;
cout << " \t\t\t\t| Made By -------> Asad Ali |" << endl;
cout << " \t\t\t\t-----------------------------" << endl;
system("pause");
return 0; // Return a zero value to the main function
} // end main function
#include <iostream> // input output library
#include <iomanip> // library for setting precision
using namespace std;
const double pi = 3.14159; // global veriable for pi and its value cannot be changed
const double slcArea = 14.125; // global variable for area of slices and this value cannot be changed
int main() // start of main function
{
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "|\t\t\t\t\t----Pizza Pi----\t\t\t\t\t |" << endl; // Program Title
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "| This program will ask for the number of people who will attend the party & diameter of Pizza |\n";
cout << "| and then it will tell you how many pizzas you should buy for the party. |\n";
cout << "--------------------------------------------------------------------------------------------------" << endl;
double dimtr, // Here "dimtr" stands for diameter of the pizza
nSlc, // Here "nSlc" stands for number of slices of pizza
area, // Here "area" stands for the area of the pizza
nPple, // Here "nPple" stands for the number of people
nPiz, // Here "nPiz" stands for the number of pizzas
radius;
cout << "| How many people are comming to your party?\t\t\t\t\t\t |" << endl;
cout << "| ";
cin >> nPple;
cout << "| Write the dimeter in inches of pizza you want to buy. \t\t\t\t\t |" << endl;
cout << "| ";
cin >> dimtr; // Input from the user for the diameter of the Pizza
radius = dimtr / 2; // converts diameter of pizza into radius
area = pi * pow(radius, 2); // finds the area of the piza as Area = πr2
nSlc = area / slcArea; // finds the number of slices can be takken from one pizza
nPiz = (nPple * 4) / nSlc;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "| \t\t\tThe pizza of diameter " << dimtr << " will have about " << setprecision(1) << fixed << nSlc << " slices\t\t\t |" << endl;
cout << "|\t\t\t If each person eats 4 slices in the party\t\t\t\t |" << endl;
cout << "| \t\tthe you should buy about " << nPiz << " pizzas to fullfil the need of the party\t\t |" << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << endl;
cout << " \t\t\t\t-----------------------------" << endl;
cout << " \t\t\t\t| Made By -------> Asad Ali |" << endl;
cout << " \t\t\t\t-----------------------------" << endl;
system("pause");
return 0; // Return a zero value to the main function
} // end main function
OutPut of this code / problem will go like this:
Now we ENTER 12 number of people
Then we ENTER 8 inches as diameter of pizza
and result goes as follows: