fork download
  1. //Diego Martinez CSC5 Chapter 3, P. 147,#18
  2. /*******************************************************************************
  3. * Sizing pizza pies
  4. * ______________________________________________________________________________
  5. * This program a program to calculate the number of slices a pizza of any size
  6. * can be divided into.
  7. *
  8. * Computation is based on the Formula:
  9. * radius = diameter / 2
  10. * Area = π × r²
  11. * numberOfSlices = pizzaArea / 14.125
  12. *______________________________________________________________________________
  13. * INPUT
  14. * The user enters the diameter of the pizza.
  15. *
  16. * OUTPUT
  17. * Displays how many slices the pizza can make.
  18. *******************************************************************************/
  19. #include <iostream>
  20. #include <cmath>
  21. using namespace std;
  22.  
  23. int main() {
  24. const double PI = 3.14159;
  25. const double SLICE_AREA = 14.125; // area of one slice in square inches
  26.  
  27. double diameter, radius, pizzaArea;
  28. int numberOfSlices;
  29.  
  30. // A) Ask the user for the diameter
  31. cout << "Enter the diameter of the pizza in inches: ";
  32. cin >> diameter;
  33.  
  34. // Calculate radius
  35. radius = diameter / 2;
  36.  
  37. // Calculate area of pizza
  38. pizzaArea = PI * pow(radius, 2);
  39.  
  40. // B) Calculate number of slices
  41. numberOfSlices = pizzaArea / SLICE_AREA;
  42.  
  43. // C) Display result
  44. cout << "A pizza with a diameter of " << diameter
  45. << " inches can be divided into "
  46. << numberOfSlices << " slices." << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter the diameter of the pizza in inches: A pizza with a diameter of 6.95315e-310 inches can be divided into 0 slices.