### Reverse programming!

Shipping Widgets.

We can ship up to 10 widgets in boxes of three sizes:

A small box holds 4 widgets.
A medium box holds 6 and a large box 10.

Unused space in the box is filled with foam blocks
which are the same size as a widget.

Input the number of Widgets to ship: 4
A small box was used to ship 4 units.

Input the number of Widgets to ship: 8
A large box was used to ship 8 units.

Input the number of Widgets to ship: 5
A medium box was used to ship 5 units.

Input the number of Widgets to ship: 10
A large box was used to ship 10 units.

Input the number of Widgets to ship: 1
A small box was used to ship 1 units.

Input the number of Widgets to ship: 0

A total of 28 widgets were shipped, using
2 small boxes, 1 medium boxes, 2 large boxes,
and 6 foam packing blocks.

Press any key to continue . . .

That is the running program.
I understand the math, I just need help on the programming part of it.
How would we program something like this?
thanks!
pretend you're the computer: write out pseudocode as a line by line step of how you would try to do the problem. You're seriously not even trying, at least show us you tried to come up with a method to solve this. Even if you have no idea how.

Seriously I wish I had the discipline to write pseudocode when I started out. You'll be lightyears ahead if you train yourself to do that.
widgets:
A small box would be in the 1-4 range
a medium box would be in the 5-6 range
a large box would be in the 7-10 range
foam:
small box: 4-number entered
medium box: 6-number entered
large box: 10-number entered

how do i tell the computer which number represents which box and how do i have the computer keep track during the looping program?
Last edited on
Alright at least you broke it down:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````int num_widgets=0; printf("How many widgets do you need shipped?"); scanf("%d",&num_widgets); int num_large_boxes,num_med_boxes,num_small_boxes = 0; if(num_widgets<=4) { num_small_boxes=1; printf("One small box was used\n"); printf("%d blocks of foam were used.\n",4-num_widgets); } else if(num_widgets<=6) { num_medium_boxes=1; printf("One medium box was used\n"); printf("%d blocks of foam were used.\n",6-num_widgets); } else if(num_widgets<=10) { num_large_boxes=1; printf("One large box was used\n"); printf("%d bloxks of foam were used.\n",10-num_widgets); } else { num_large_boxes = num_widgets / 10; int num_rest = num_widgets % 10; //then the same if/else if/else: if((num_rest<=6)&&(num_rest>0)) { num_medium_boxes=1; num_rest=num_rest-6; } if((num_rest<=4)&&(num_rest>0)) { num_small_boxes=1; num_rest=num_rest-4; } int foam_used = (10*num_large_boxes) + (6*num_medium_boxes)+(4*num_small_boxes) - num_widgets; //do whatever } //maybe some other stuff ``````

I don't know if this will completely answer your question but there is enough there so you can research or figure out the rest.
Last edited on
Topic archived. No new replies allowed.