(The file should have your program and the console input/output of your program)
ID: 3797658 • Letter: #
Question
(The file should have your program and the console input/output of your program)
3.18: Pizza Pi
Joe’s Pizza Palace needs a program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps:
Ask the user for the diameter of the pizza in inches.
Calculate the number of slices that may be taken from a pizza of that size.
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 = "pi r squared" where pi is approximately 3.14159 and r is the radius (half the the diameter).
Explanation / Answer
// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string.h>
#define PI 3.14159
#define SLICE_AREA 14.125
using namespace std;
int main()
{
double radius_pizza;
double area_pizza;
double slice_perPizza;
double diameter;
cout << "Enter pizza diameter: ";
cin >> diameter;
radius_pizza = diameter / 2;
area_pizza = PI*radius_pizza*radius_pizza;
slice_perPizza = area_pizza / SLICE_AREA;
cout << int(slice_perPizza) << " slices" << endl;
return 0;
}
/*
output:
Enter pizza diameter: 10
5 slices
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.