Programming Challenge Chapter 3 – Q #19 How Many Pizzas? – Tony Gaddis – Starting Out With C++
Problem: -
Programming Challenge 18 (Pizza Pi)
Solution: -
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const float PIZZA_AREA = 14.125,
PI = 3.14159;
float diameter;
int people;
double radius = 0.0, area = 0.0, no_of_slice = 0.0, slice_needed = 0.0, no_of_pizza = 0.0;
cout << "How Many Peopel Who
Ate The Pizza: ";
cin >> people;
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;
slice_needed = people * 4;
no_of_pizza = slice_needed / no_of_slice;
cout << setprecision(1) << showpoint << fixed;
cout << "No of Slice =
" << no_of_slice << endl;
cout << "No of Slice Needed
= " << slice_needed << endl;
cout << "No of Pizza For Order = " << no_of_pizza << 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 float constants and initialize given values.
- Declare another a float variable for input.
- Declare another a int variable for input.
- Declare five 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