fork download
  1. //Andrew Alspaugh CS1A Chapter 3. P. 147. #18
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Number of Slices Per Pizza
  6.  * __________________________________________________________________________
  7.  * This program calculates how many slices any pizza can be divided into
  8.  *
  9.  * Equation used for solving = pi(d/2)^2/14.125
  10.  * _________________________________________________________________________
  11.  * INPUT:
  12.  * Diameter :Diameter of Pizza
  13.  * OUTPUT:
  14.  * Area :Area of Pizza
  15.  * Slices :Slices per Pizza
  16.  ****************************************************************************/
  17. #include <iostream>
  18. #include <cmath>
  19. using namespace std;
  20. int main()
  21. {
  22.  
  23. double Diameter; //Input Diameter
  24. double Area; //Output Area
  25. double Slices; //Output Slices
  26.  
  27. //Input Diameter
  28. cout<<"enter diameter of pizza"<<endl;
  29. cin>>Diameter;
  30.  
  31. //Use Diameter to Solve for Area
  32. Area = M_PI * pow((Diameter/2),2.0);
  33.  
  34. cout<<"Area of Pizza is "<<Area<<endl;
  35.  
  36. //Divide Area by 14.125 to Solve for Slices
  37. Slices = Area / 14.125;
  38.  
  39. cout<<"This Pizza has "<< Slices << " slices";
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5320KB
stdin
31
stdout
enter diameter of pizza
Area of Pizza is 754.768
This Pizza has 53.4349 slices