Distribute soda by rules

Hello,

I've been given a task to write a program which could output the biggest amount of soda that the guests of a party could drink. 'n' is the amount of boys as well as girls. Every girl needs to be allowed to drink equally as much as every other girl, every boy as much as every other boy. Men shall drink twice as much as women.

I have already came up with an idea as to how it should be done, but the code is not finished.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>

using namespace std;

int main()
{
party:
    int n;
    cin>>n;
    int capacity;
    cin>>capacity;
    int glass = 2*n;
    int boys = n;
    int girls = n;
    int glass_quantity[glass];
    int capture = 0;
    int acknowledge = -1;
    double boundary;
    for(int i  = 1; i < sizeof(glass_quantity); i++)
    {
        if(capture>capacity)
        {
            cout<<"Too much liquid has been proposed for a glass."<<endl;
            goto party;
        }
        if(capacity==capture) break;
        cin>>glass_quantity[i];
        capture+=glass_quantity[i];
        acknowledge++; //counts the amount of used glasses
    }
    int boys_maximum = 0;
    int girls_maximum = 0;
    bool enter = true; 
    for(; acknowledge > 0; acknowledge--)
    {
        if(boys_maximum!=(capture/3)*2 && enter)
        {
                boys_maximum += glass_quantity[acknowledge];
                boundary +=glass_quantity[acknowledge];
                enter = false; //Every empty glass shall not be counted twice
        }
        if(girls_maximum!=capture/3 && enter)
        {
                girls_maximum += glass_quantity[acknowledge];
                boundary +=glass_quantity[acknowledge];
        }
        enter = true;
    }
    cout<<boundary;
}


It is said that for n = 2, capacity = 4, glass_quantity[0] = 1, glass_quantity[1] = 1, glass_quantity[2] = 1, glass_quantity[3] = 1 the result should be 3. For n = 1, capacity = 5, glass_quantity[0] = 2, glass_quantity[1] = 3 the result should be 4,5.

I have no idea how do I make the program realise, for example, how much soda will not be allowed for the guests. Please, give me only some clues rather than answers.
Last edited on
I don't understand what the inputs are and what needs to be calculated.
n is both the amount of men and women, therefore there are 2*n guests.
capacity is the amount of soda available.
glass_quantity[i] is every glass that you could fill.

What needs to be calculated is the maximum amount of soda guests can drink with the assumption that every man and woman will drink as much as every other man and woman while men will drink twice as much.
Last edited on
I’m confused by your data.
So, in a party there’s a determined amount of soda (--> “soda”) [given by the user].
Men and women are the same number (--> “guests”), so total presents are “guests” x 2 [“guests” is given by the user].
Men drink double than women.

If so,
--> “soda” / 3 is the total amount of soda for women (--> “wsoda”)
--> “wsoda” / “guests” is the soda amount for each woman
--> “wsoda” x 2 is the total amount of soda for men (--> “msoda”)
--> “msoda” / “guests” is the soda amount for each man

What else do you need?

(Please note: “guests” can be an ‘int’, but I think “soda”, “wsoda”... should be ‘double’).
Well, ok, now however another problem shows up. for_women is an arbitrary number and I need to make one like 1.666667 to be 1.5 so that
for an input
1 5
2 3

The result will be 4.5. This is not achievable since I can only round one up to an integer using ceil() and floor().


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
party:
    int n;
    int w;
    cin>>n;
    cin>>w;
    int glasses = 2*n;
    int each[glasses];
    int men = n;
    int women = n;
    double compare = 0;
    for(int i = 0; i < glasses; i++)
    {
        if(w==compare)break;
        if(compare>w) goto party;
        cin>>each[i];
        compare+=each[i];
    }
    double for_women=compare/3;
    cout<<'\n'<<for_women<<endl;
    double for_men=for_women*2;
    double outcome = for_men+for_women;
    cout<<fixed<<setprecision(1)<<outcome;
    cin.get();
    return 0;
}
Last edited on
What about describing us better what you're trying to achieve? From your initial description of the assignment, I can't work out why you need to calculate 'glasses' or 'compare' - and perhaps I'm not the only one.
Registered users can post here. Sign in or register to post.