Programming Challenge Chapter 3 – Q #18 Pizza Pi – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #18 Pizza Pi – Tony Gaddis – Starting Out With C++



Problem: -

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: 
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: 

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

  1. Add two header file for math and pattern.
  2. Declare two double variables for input.
  3. Declare another a int variable for input.
  4. Declare three double variable for calculations.
  5. Take input one by one from user.
  6. Calculate the values.
  7. Calculate the values by using given formula.
  8.  In last, display output on the screen in a pattern.
  9. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Post a Comment

0 Comments