Jump to content

Interesting problem - calculating a single person supplement in hotel rooms


kalemanzi

Recommended Posts

Hi there

i have encountered a problem a little out of my league. Any help would be highly appreciated

I don´t expect of anybody to give me complete code (would be nice though) but if I could just get a starting point or some ideas to get going I would be very grateful.

 

this is the scenario.

I have a guesthouse. There are several rooms. Some of the rooms have 2 beds and some 4 beds.

The rate per person sharing is $100 for instance.  When you stay alone, you have to pay an extra $50 for the room, so it costs you $150.

 

Say we have 4 rooms:

room1 = 2 beds

room2 = 2 beds

room3 = 4 beds

room4 = 2 beds

 

Now somebody wants to make a booking and they tell us they are 3 people and they select 2 rooms. This would mean that there is going to be one of the rooms that will have a single occupant in it which will make the overall price $50 more expensive.

Let´s say they selected any two rooms (okay, room 1 and room3)

Room 1 has 2 beds and room 3 has 4 beds. They could all fit into the single room, but they deliberately chose two seperate rooms so we assume that two people want to stay together and the one person wants to be alone.

 

the script needs to calculate it like this. room1($100 + $100) + room2($100 + $50) = total ($350)

It could be rewirtten like this as well: (number_of_people*$100) + (number_of_singles*$50)

 

how do I calculate the value of number_of_singles?

 

Possible inputs would be:

4 people and 4 rooms (room1,2, 3 and 4)

4 people and 2 rooms (room1, 2)

5 people 3 rooms (room1, room2, room4)

 

In my head I can think that for starters, based on the rooms they selected, each room must at least have one occupant. Next the remaining guest must be placed at the next logical place (based on which room was selected higher up in the list) that has a space open. once all the guests are allocated to a room, it can be checked which rooms are remaining with single occupants. Then the overall fee must be calculated by multiplying the number of guests with the per person sharing fee and then the single person fee must be added to that based on how many rooms have only 1 occupant remaining.

 

HELP!

thanks

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.