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;
Comments
Leave a comment