50.4k views
9 votes
When you purchase donuts, they come in boxes of 12, so 24 donuts take 2 boxes. All donuts need to be in a box, so if you buy 13 donuts, you'll get 2 boxes with 12 in the first box and 1 in the second. If the integer variable numberOfDonuts contains the positive number of donuts purchased, which of the following will correctly give the number of boxes needed?

a. int numberOfBoxes = 1 + numberOfDonuts / 12;
b. int numberOfBoxes = numberOfDonuts / 12 + numberOfDonuts % 12;
c. int numberOfBoxes = numberOfDonuts / 12;
d. int numberOfBoxes = (numberOfDonuts + 11) / 12;

User Usersam
by
4.5k points

1 Answer

8 votes

Answer:

d) int numberOfBoxes = (numberOfDonuts + 11) / 12

Step-by-step explanation:

Hope this helps

User Ankit Zalani
by
4.0k points