0
$\begingroup$

I am making an application to divide bills. I have the following problem:

Jhon and Paul were to a pub , and they consumed 20 beers. James get in the bar and they consumed ten more beers.

How much Paul have to pay ?

I tried this approach:

Jhon and Paul drank all beers so they have to pay all of them = 1

James just drink 1/3 of the beers.

So james have to pay 30/(1 + 1 + 0,33) = 30/2,33 = 12,87

I know the correct result is 13,33

What i'm doing wrong?

EDIT

I know i can calculate the price like 20/2 + 10/3. But i'm doing an algorithm and this is hard to implement that.

That's why i wanna know what i'm doing wrong.

EDIT

The correct formula is:

James drank 1/3 of the beers, but have other 2 people drank with him so, it's not 10/30 its (10 - 2,33) / 30 = 0,25

Paul have to pay 30 / (1 + 1 + 0,25)

  • 0
    You want a formula for your algorithm, but you ar$e$ not saying what the input for your algorithm is. What are your variables?2012-11-24

2 Answers 2

2

So Paul has to pay 10 beers (20/2 because there were only Paul and John at the beginning) and "3.33" because James came there so there were Paul,John and James now and they drank 10 beers so - $10/3 = 3.33$ .

$10+3.33 = 13.33$

For algorithm all you have to do is implement following equation in cycle, where in every step of cycle you will input new values for $b$ and $n$ and before cycle give $S=0$ .

$S = S+\frac bn$

where

S - sum of bills
b - number of beers in one "cycle" (20 at beginning, then 10 when james came etc.)
n - number of people

  • 0
    You're welcome. s,b,n are real numbers when declaring.2012-11-24
0

Assuming they all drank exactly the same ammount of beer that were served to them:

== Each of Jhon and Paul drank 10 + 3.333 = 13.333 beers and this each must pay.

== James drank 3.333 beers and this he pays.

  • 0
    @GuilhermeTorresCastro: Only you can answer that -- since you haven't really explained what it is, nor how on earth you could expect it to be right -- but some hints based on your single example would be that (a) it seems to produce the same answer for each of the three drinkers, (b) the "correct answer" you compare to is clearly absurd, since it has James paying for 13 beers while only 10 were consumed while he was present at all, (c) if everyone pays for 12.87 beer, there'll be money for 38.61 beers on the table at the end but only 30 were consumed (the waiter pockets the rest?)2012-11-24