fork download
  1. //Micah Krosby CS1A Ch. 3, P. 147, # 18
  2. /*******************************************************************************
  3.  *
  4.  * CALCULATE SLICE QUANTITY IN PIZZA
  5.  * _____________________________________________________________________________
  6.  *
  7.  * This program finds the amount of slices of a specified slice area that should
  8.  * be cut into a pizza of a specified diameter.
  9.  *
  10.  * FORMULAE-
  11.  * Area = PI * (Diameter/2)^2
  12.  * Slice Quantity = Pizza Area / Slice Area
  13.  * _____________________________________________________________________________
  14.  *
  15.  * INPUTS-
  16.  * diameter : Diameter of pizza requested
  17.  * sliceArea : Given area of pizza slices
  18.  *
  19.  * OUTPUTS-
  20.  * pizzaArea : Area of pizza requested
  21.  * sliceNumber : Number of slices in pizza requested
  22.  *
  23. *******************************************************************************/
  24.  
  25. #include <iostream>
  26. #include <iomanip>
  27. #include <cmath>
  28. #define PI 3.14
  29. using namespace std;
  30.  
  31. int main() {
  32. float diameter; //INPUT- Diameter of pizza
  33. float sliceArea; //INPUT- Area of one slice
  34. float pizzaArea; //OUTPUT- Area of pizza
  35. float sliceNumber; //OUTPUT- Number of slices in pizza
  36.  
  37. //Initialize inputs
  38. cout << "Diameter?" << endl;
  39. cin >> diameter;
  40. cout << endl;
  41. sliceArea = 14.125;
  42.  
  43. //Calculate outputs
  44. pizzaArea = PI * pow(diameter / 2, 2);
  45. sliceNumber = pizzaArea / sliceArea;
  46.  
  47. //Formatted output
  48. cout << "The amount of slices that should be cut into this pizza is "
  49. << fixed << setprecision(1) << sliceNumber << ".";
  50. return 0;
  51. }
Success #stdin #stdout 0s 5280KB
stdin
20
stdout
Diameter?

The amount of slices that should be cut into this pizza is 22.2.