fork download
  1. //Xinnuo Wang CS1A chapter 3 , P.147, #18
  2. //
  3. /*******************************************************************************
  4. *
  5. * Caculate the number of slices a pizza
  6. *-------------------------------------------------------------------------------
  7. * This program to calculate the number of slices a pizza of any size
  8. * can be divided into.
  9. *
  10. * computation is based on the formula:
  11. * Area = π x r^2
  12. *-------------------------------------------------------------------------------
  13. * INPUT
  14. * diameter : The diameter of the pizza in inches
  15. * radius : The radius of the pizza in inches
  16. * area : The area of the pizza
  17. * OUTPUT
  18. * numb : The number of slices a pizza of any size
  19. *
  20. *******************************************************************************/
  21. #include <iostream>
  22. #include <cmath>
  23. using namespace std;
  24.  
  25. int main() {
  26. double diameter; //INPUT - The diameter of the pizza in inches
  27. double radius; //INPUT - The radius of the pizza in inches
  28. double area; //INPUT - The area of the pizza
  29. double numb; //OUTPUT - The number of slices a pizza of any size
  30. //
  31. //Input Data
  32. cout<< "Enter diameter of the pizza in inches" <<endl;
  33. cin >> diameter;
  34. //
  35. //Compute Radius
  36. radius = diameter/2;
  37. //
  38. //Compute Area
  39. area = 3.14156 * pow(radius,2);
  40. //
  41. //Compute the Number of slices
  42. numb = area/14.125;
  43. //
  44. //Output Result
  45. cout << "The number of slices is :"<< numb<<endl;
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5292KB
stdin
12
stdout
Enter diameter of the pizza in inches
The number of slices is :8.00681