fork download
  1. //Micah Krosby CS1A Ch. 3, P. 147, # 19
  2. /*******************************************************************************
  3.  * CALCULATE AMOUNT OF PIZZAS FOR A GROUP
  4.  * _____________________________________________________________________________
  5.  * This program finds the amount of pizzas a group would need depending on pizza
  6.  * diameter and the amount of people in the group.
  7.  *
  8.  * FORMULAE-
  9.  * Area required = people * slices per person * single slice area
  10.  * Pizzas required = area required / (pi * (diameter / 2)^2)
  11.  * _____________________________________________________________________________
  12.  *
  13.  * CONSTANTS-
  14.  * MATH_PI : Value of pi rounded to nearest hundredth
  15.  * SLICES_PER_PERSON : Amount of slices one person will eat
  16.  * SINGLE_SLICE_AREA : Amount of area one slice might have
  17.  *
  18.  * INPUTS-
  19.  * attendance : Amount of people attending
  20.  * diameter : Requested diameter of pizzas
  21.  *
  22.  * OUTPUTS-
  23.  * sliceArea : Amount of pizza area required
  24.  * pizzaQuantity : Amount of pizzas required
  25.  *
  26. *******************************************************************************/
  27.  
  28. #include <iostream>
  29. #include <iomanip>
  30. #include <cmath>
  31. #define MATH_PI 3.14 //CONST- Pi rounded to the nearest hundredth
  32. #define SLICES_PER_PERSON 4 //CONST- Amount of slices per person
  33. #define SINGLE_SLICE_AREA 14.125 //CONST- Amount of area in one slice
  34. using namespace std;
  35.  
  36. int main() {
  37. int attendance; //INPUT- Amount of people attending
  38. float diameter; //INPUT- Diameter of pizzas requested
  39. float sliceArea; //OUTPUT- Area of pizzas requested
  40. float pizzaQuantity; //OUTPUT- Quantity of pizzas required
  41.  
  42. //Initialize input variables
  43. cout << "How many people will be attending?" << endl;
  44. cin >> attendance;
  45. cout << "What diameter shall the pizzas be?" << endl;
  46. cin >> diameter;
  47.  
  48. //Calculate output variables
  49. sliceArea = attendance * SLICES_PER_PERSON * SINGLE_SLICE_AREA;
  50. pizzaQuantity = sliceArea / (MATH_PI * pow(diameter / 2, 2));
  51.  
  52. //Output
  53. cout << "The amount of pizzas required will be " << ceil(pizzaQuantity)
  54. << endl;
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5280KB
stdin
5
5
stdout
How many people will be attending?
What diameter shall the pizzas be?
The amount of pizzas required will be 15