fork download
  1. //Ava Huntington CS1A Chapter 3 Homework P. 147, #18
  2. //
  3. /*******************************************************************************
  4.  * CALCULATE PIZZA SLICES
  5.  * _____________________________________________________________________________
  6.  * This program will calculate the number of evenly sized slices of pizza
  7.  * given the pizzas diameter.
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * pizzaDiameter: Given diameter of pizza
  11.  * pizzaArea: Area of pizza based on given diameter
  12.  * sliceArea: Specific area of a single pizza slice
  13.  * pi: Definition of Pi
  14.  *
  15.  * OUTPUT
  16.  * numberOfSlices: Number of pizza slices based on diameter of pizza
  17.  ******************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. #include<cmath>
  21.  
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26.  
  27. float pizzaDiameter; //INPUT : Given of diameter of pizza
  28. float pizzaArea; //INPUT : Area of pizza based on diameter
  29. float sliceArea; //INPUT : Specified area of a pizza slice
  30. float pi; //INPUT : Definition of Pi
  31. float numberOfSlices; //OUTPUT : User chosen city
  32.  
  33. //Prompt to aquire diameter of pizza
  34. cout << "What is the diameter of the pizza in inches? "<<endl;
  35. cin >> pizzaDiameter;
  36.  
  37. //Defining pi
  38. pi = 3.14159;
  39.  
  40. //Equation to find the area of the pizza
  41. pizzaArea = pow((pi*(pizzaDiameter/2)),2);
  42.  
  43. //Defining the area of a slice of pizza
  44. sliceArea = 14.125;
  45.  
  46. //Equation to find amount of slices
  47. numberOfSlices = pizzaArea/sliceArea;
  48.  
  49. //Final ouput, slices of pizza based on given diameter
  50. cout << "Based on the given diameter, the pizza can be divided into "<<
  51. setprecision(3)<<numberOfSlices<< " slices."<<endl;
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5280KB
stdin
12
stdout
What is the diameter of the pizza in inches? 
Based on the given diameter, the pizza can be divided into 25.2 slices.