fork download
  1. //Andrew Alspaugh CS1A Chapter 3. P. 147. #18
  2. //
  3. /*****************************************************************************
  4.  *
  5.  *Calculate Number of Slices
  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. float Diameter; //Input Diameter
  24. float Area; //Output Area
  25. int Slices; //Output Slices
  26.  
  27.  
  28. //Input Diameter
  29. cout<<"enter diameter of pizza"<<endl;
  30. cin>>Diameter;
  31.  
  32. //Use Diameter to Solve for Area
  33. // Area = M_PI * pow((Diameter/2),2.0);
  34. Area = M_PI * Diameter*Diameter/4;
  35. cout<<"Area of Pizza is "<<Area<<endl;
  36.  
  37. //Divide Area by 14.125 to Solve for Slices
  38. Slices = Area / 14.125;
  39.  
  40. cout<<"This Pizza has "<< Slices << " slices";
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5320KB
stdin
18
stdout
enter diameter of pizza
Area of Pizza is 254.469
This Pizza has 18 slices