Hi I had a few quick questions about this program that I'm just about to write. The program itself looks fairly easy, for the calculation I'm not so sure.

Problem Statement:

We have been hired to write a program to determine the number of cases required to store boxes of cookies. A case of cookies can store 10 boxes of cookies. The user of the program will enter the number of cookies that have been purchased. The program should print out both the number of boxes of cookies and also the number of cases required.


Is it just me, or am I going to have to assume the number of cookies that equal 1 box?

Also what would I do with the left over cookieS?
For example, if someone enters 75 cookies that would be be 7.5 boxes.

Get what i mean? What would I do with the left over?
Just want to understand the problem clearly before I get started. Writing the program doesn't look bad at all.

guess its time to ask the instructor what to do about your questions.

We have been hired to write a program to determine the number of cases required to store boxes of cookies. A case of cookies can store 10 boxes of cookies. The user of the program will enter the number of cookies that have been purchased. The program should print out both the number of boxes of cookies and also the number of cases required.

The question is unclear in the part where it says "A case of cookies can store 10 boxes of cookies." I would assume as you do that a client would buy a whole box of cookies, not 1 cookie at a time.

The part where each case contain 10 boxes is simple. If the total boxes sold is 75, you need 8 cases in order to store all of those boxes. Think about it as real life situation. You cannot use 7 cases to store all of them, right? You need to round the number up to get the number of boxes correctly.

I asked my professor and he said to assume that each box will contain 10cookies.

so that means:
10 cookies = 1 box
10 boxes = 1 case

The user is inputting the number of cookies, so we don't have to output the number of cookies, just the number of boxes and cases, which the program will calculate.

Now, for the calculation I'm not sure if I have got the right idea.
So here's my defining diagram:


INPUT
#ofcookies

PROCESSING
-prompt user for data
-read the data
-calculate the number of boxes
-calculate the number of cases
-output information

OUTPUT
#ofboxes
#ofcases


I'm thinking I would be using the math.round() method to round up the number of boxes and cases, right?

Are these the right formulas for the calcuations:
#ofboxes = #ofcookies/10
#ofcases = #ofboxes/10

Would you say that's correct information that I have gathered to get on the right path of this program?
It looks like it's going to be a short program, is it?
Thank you for all your feedbacks!

Think practically...do you throw away remaining cookies?? I guess you don't need to round off the no. of boxes/cases.
Lets take a small example. Say the #ofCookies = 25. Then how many boxes do you need to cover all the cookies? Well, you need 3. Two boxes will contain 10 cookies each and one box will hold the remaining which is 5.
Now ask your professor whether he meant that each box will contain at most 10 cookies or exactly 10 cookies. I believe he meant the former.
In that case your output must be:

#ofBoxes = 3
#ofCases = 0

But in case he meant the latter, then you are absolutely right. But then it makes the program too simple and I don't think he wanted you to do simple divisions. And, btw you don't even have to use math.round(), just simply using ints will do the trick.


But think about it, the way you would have done in a practical situation.
Good luck.

Yes, he replied to my email and said that the box and cases can contain 10 at the most.

I'm confused of how that makes a difference to the logic. Either way to me the formula seems to work just fine logically..what piece of this puzzle am I missing?

You don't use parts of boxes, thus, even if you only want to store one extra cookie, an entirely new box will be used. Start with the necessary division, then round up keeping this is mind and you should be fine.

If its 10 at the most (which i told you, should be) then i think the example was pretty explanatory, wasn't it??
okay lets go through it once again:
we have 25 cookies
how can you divide them knowing that each box can hold at the most 10 cookies?
you start putting in cookies in the 1st box. Once you've put 10 cookies, it can hold no more and you seal it.
You have 15 cookies left.
You start filling the 2nd box. It can again hold up to 10 cookies. You give it that and seal it.
You are left with 5 cookies.
Now you probably wont throw these remaining cookies nor you can just hand it over to your customer(or whoever) and ask them to take 'em in their pockets. (assuming you are too polite to do that)
So what do you do?
You take a fresh box and put those remaining 5 cookies in it, and then give your customer the THREE BOXES wrapped in ONE CASE with a smile.
Now in this case, you don't have 10 boxes but assuming your cases can also contain at the most 10 boxes you'll need one case. (i forgot to mention this in the last post. Sorry)

So here's a summary
#ofCookies = 25
#ofBoxes = 3
#ofCase = 1

here's another test case:
#ofCookies = 127
#ofBoxes = 13
#ofCases = 2

Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.