fork download
  1. // Marvyn De La Torre CS1A Chapter 3, P.147, #18
  2.  
  3. /*************************************************************
  4. // Calculate Pizza Slices
  5. //
  6. // This program displays the number of slices that can be made
  7. // from a pizza based on its diameter.
  8. //
  9. // Input:
  10. // Pizza diameter
  11. //
  12. // Output:
  13. // Number of pizza slices
  14. *************************************************************/
  15.  
  16. #include <iostream>
  17. #include <iomanip>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. double diameter;
  23. double radius;
  24. double area;
  25. double slices;
  26. const double PI = 3.14159;
  27.  
  28. cin >> diameter;
  29.  
  30. radius = diameter / 2;
  31. area = PI * radius * radius;
  32. slices = area / 14.125;
  33.  
  34. cout << fixed << showpoint << setprecision(1);
  35. cout << "The pizza can be divided into " << slices << " slices.";
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 5324KB
stdin
12
stdout
The pizza can be divided into 8.0 slices.