Programming Challenge Chapter 3 – Q #18 Pizza Pi – Tony Gaddis – Starting Out With C++
- 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:
Solution: -
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const float PIZZA_AREA = 14.125,
PI = 3.14159;
float diameter;
double radius = 0.0, area = 0.0, no_of_slice = 0.0;
cout << "What is The Diameter
of Pizza in Inches: ";
cin >> diameter;
//Calculation
radius = diameter / 2.0;
area = PI * pow(radius, 2);
no_of_slice = area / PIZZA_AREA;
cout << setprecision(1) << showpoint << fixed;
cout << "No of Slice = " << no_of_slice << endl;
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Input is highlighted with yellow color.
Explanation of this Solution
- Add two header file for math and pattern.
- Declare two double variables for input.
- Declare another a int variable for input.
- Declare three double variable for calculations.
- Take input one by one from user.
- Calculate the values.
- Calculate the values by using given formula.
- In last, display output on the screen in a pattern.
- Return 0 to the main function.
0 Comments