# Thread: Need a little help

1. ## Need a little help

Could someone please give me an idea on how to do this?

Suppose you have a group of people that needs to be transported on buses and vans. You can charter a bus only if you can fill it. Each bus holds 50 people. You must provide cans for the 49 or fewer people who will be left over after you charter buses. Write a program that accepts a number of people and deterimins how many buses must be chartered and reports the number of people left over that must be placed on bans.

Also each van can hold 15 people. How many vans will be required?

Not looking for you guys to do it or anything...just need some help on where to start.

2. This is somewhat similar to questions that ask you to make change...

So anyway, what are you plans? Any ideas?

3. First, divide the amount by your 50, then extract the fraction from the float/double.
The whole left over is the amount of buses. Do the same with the extraction.

I could write the whole program for you in less than 5 minutes, but this does sound like homework to me.

4. Oh ok. How would I incorporate the modulus operator in the code? I'm supposed to use it.

5. You can use the &#37; to get the remainder of people that have to be transported on vans.

6. Ok gotcha.

I got the divide my amount by 50, but can you elaborate on what you mean by extract the fraction from the float/double.

7. Actually I think that extracting a fraction is a big mistake. Use some integer math, because dealing with parts of people will only make your results fuzzy.

I don't see why you can't simply
1. Divide the group by the number of bus seats to find the number of buses.
2. Take away the people on buses from the group to find the leftovers.
3. Divide the leftovers by the number of seats in a van to find the number of vans.

In my solution, it turns out that 145 people will need 2 buses and 3 vans to go on vacation, and I made sure it added up.

8. Here's how you find out how many people are left over.
Code:
`int nLeftOverPeople = int(float(AMOUNT) &#37; 50.0);`

9. fmod() is better at it.

10. Originally Posted by Sembhi
You must provide cans for the 49 or fewer people who will be left over after you charter buses.
Their consolation prize is a can? That's harsh.

11. Originally Posted by citizen
fmod() is better at it.
I agree with that, but there's absolutely no reason to use floating point in this case, as citizen pointed out before. It just a possible cause for strange errors as the results are not precise in floating point, and you can end up with results caused by rounding down.

--
Mats