I am having difficulty with a program in my CS class right now and I am wondering if you guys could help.

Basically, I need to find the length/width (should be equal) of the 4 corners(I'll call this variable 'x') of a piece of cardboard, to cut them out to fold the sides up into a tray (hopefully you guys can understand that description :/). The user inputs the total length of both sides of the box, and I need to figure out how to calculate the smallest possible length that x could be.

I have currently figured out how to find x if length and width are different sizes, but when they are equal I cannot figure out how to find it.

Ex. of how to find when they are different sizes:

If L > W

D= L-W

Df= D**.5

And I believe that's all I need to do (sorry I dont have the code w/ me and I wasn't at school today so it's not really fresh in my head).

Do you guys have any idea how I can figure it out when the sides are equal? I'm sorry that my description was awful, just ask if you need me to clarify something.

Recommended Answers

All 2 Replies

Your example probably doesn't handle the case L<W, though that's a simple fix.

I don't think I know what a tray is. If you hand me a 6-inch square of cardboard and a pair of scissors, I would cut out a 1-inch by 1-inch square at each of the 4 corners. Then I fold up all 4 sides and voila, a tray. But obviously that's not consistent with the rest of the problem since my choice of 1 inch at the corners could be replaced by 1/2 inch or 1 millimeter or 1 micron, etc.

Yea, it covers L <W, I just wanted to show how I got my answer. When L and W are equal that doesn't work though, as there is no difference :/

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.