Joe\'s Pizza Palace needs a program to calculate the number of slices a pizza of
ID: 3628683 • Letter: J
Question
Joe's Pizza Palace needs a program to calculate the number of slices a pizza of any sizecan be divided into. The program should perform the following steps:
A) Ask the user for the diameter of the pizza in inches.
B) Calculate the number of slices that may be taken from a pizza of that size.
C) Display a message telling the number of slices.
To calculate the number
of slices that may be taken from the pizza, you must know
the
following facts:
• Each slice should have an area of 14.125 inches.
• To calculate the number of slices, simply divide the area of the pizza by 14.125.
• The area of the pizza is calculated with this formula:
Area = p*r^2
NOTE: 1t is the Greek letter pi. 3.14159 can be used as its value . The variable r is the
radius of the pizza. Divide the diameter by 2 to get the radius.
Make sure the output of the program displays the number of slices in fixed point
notation, rounded to one decimal place of precision. Use a named constant for pi.
Explanation / Answer
#include<iostream>
using namespace std;
#include
int main()
{
const float PI = 3.14159;
const float SLICE_SIZE = 14.125;
float rad, totalArea, dia, slices;
cout << "Joe's Pizza Palace requires " << SLICE_SIZE;
cout << " square inches per slice." << endl;
cout << "What is the diameter of your pizza?" << endl;
cin >> dia;
rad = dia / 2;
totalArea = PI * pow(rad,2);
slices = totalArea / SLICE_SIZE;
cout << “You should divide that pizza into ” << slices << ” slices.” << endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.