Answer to Question #89076 in C++ for Ajay

Question #89076
You are a Caterer for Pizza Parties. You would like to have a program to calculate how many pizzas to order for a given number of people and the cost. You will provide two types of pizza: combination and cheese.

You would also like to know how many pizza slices will be left over at the end of the party.

Things you will prompt for in the program:

number of people at the party

cost for a cheese pizza

cost for a combination pizza

percentages of pizzas that need to be cheese pizzas and combination pizzas

Assume that pizzas will be cut in to 8 slices each.
1
Expert's answer
2019-05-06T12:54:41-0400

The toughest part is to calculate amount of pizzas of each type based on their percentage. Lets assume we have n people that eat only once and pizza is divided into 8 pieces. Amount of all pizzas would be (n + 8 - 1) / 8. Bias takes care of missed pizza. Ex: 10 people, if we divided without adding the bias, we would get wrong result (correct - 1).


Lets include percentage to out calculation, we have to multiply total amount of pizzas by cheese pizza persentage to get their amount. And then subtract recieved amount from total amount to get combined.


Total cost and slices left are obvious.

  /* calculate amount of cheese pizzas */
  int cheesePizzas = round(double((people + SLICES - 1) / SLICES) * double(cheesePer / 100.0));
  /* calculate amount of combined pizzas */
  int combPizzas = (people + SLICES - 1 - cheesePizzas * SLICES) / SLICES;

  /* cheese total cost */
  double cheeseTotalCost = cheesePizzas * cheeseCost;
  /* combined total cost */
  double combTotalCost = combPizzas * mixCost;

  /* slices left */
  int slicesLeft = (cheesePizzas + mixCost) * SLICES - people;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS