A quick programming question

This is a discussion on A quick programming question within the C Programming forums, part of the General Programming Boards category; Now, I don't want anyone to do my homework for me, but I was hoping someone could give me some ...

  1. #1
    Unregistered
    Guest

    A quick programming question

    Now, I don't want anyone to do my homework for me, but I was hoping someone could give me some insite on how to do a program that was assigned to me. What I have to do is ask the user to enter the amount of, lets say, widgets that are to be sent out to businesses. There are 4 containers that these widgets can be sent in : Huge container that holds 50 ; a Large container that holds 20; A medium container that holds 5; and a container that can hold one widget. The program has to be written in a way that the shipment is sent using the minimum amount of containers and with the minimum amount of waste. Any ideas would be great. I've been trying to use the Mod Operator (Ex. 50 % 4)..It doesn't seem to be affective. Thanks

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Let's say x is the number of widgets...

    x / 50 == the number of size 50 containers to use
    x % 50 == the number of widgets left over

    You'll prolly want to start with the largest containers, and work your way down.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Unregistered
    Guest
    I tried that. It was placing most of the containers into the Huge containers, and some in the large...but none in the medium or small. And since, we have to use the minimum amount of containers, it important to use them all in some equal form.

    Thanks for replying. This is my code thus far.





    #include <stdio.h>
    #define huge 50
    #define large 20
    #define medium 5
    #define small 1
    int main()

    {

    int doofs;
    int x;
    int y;
    int z;
    int w;
    int v;
    int f;
    int m;
    int p;


    printf("How many dooflingies have to be shipped out? :");
    scanf("%d",&doofs);

    x = doofs/huge;
    v = doofs % huge;
    y = v/large;
    f = doofs % large;
    z = y/medium;
    p = doofs % medium;

    w = z/small;
    m = doofs % small;


    printf("\n\n");

    printf("You can transport %d dooflingies in the Huge containers\n",x);
    printf("You can transport %d dooflingies in the Large containers\n",y);
    printf("You can transport %d dooflingies in the Medium containers\n",p);
    printf("You can transport %d dooflingies in the Small containers\n",m);


    return 0;}

  4. #4
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    I suppose it depends on the definition of waste (is it ideal to send the fewest boxes, or have the smallest amount of unused space?). If you don't want any unused space in your shipment of widgets, you could try somthing like this:

    Code:
    while ( WidgetsToSend )
    {
      if ( WidgetsToSend >= 50 )
      {
        Box50++;
        WidgetsToSend -= 50;
      }
    
      else if ( WidgetsToSend >= 20 )
      {
        Box20++;
        WidgetsToSend -= 20;
      }
     
      else if ( WidgetsToSend >= 5 )
      {
        Box5++;
        WidgetsToSend -= 5;
      }
     
      else if ( WidgetsToSend >= 1 )
      {
        Box1++;
        WidgetsToSend -= 1;
      }
    }
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21