Very confused , Vector

Jun 19, 2019 at 10:50pm
nevermind
Last edited on Jun 19, 2019 at 11:15pm
Jun 19, 2019 at 11:10pm
Start a skeletal program. Show us a main function, and include the appropriate headers for the library functions you've been told to use.

Declare the Lotto function and declare the winners vector.

Get that started, post it, and come back for more.
Jun 20, 2019 at 12:32am
nevermind

<grin> nonetheless:
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
// Example program
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;

vector <unsigned> Lotto(unsigned pool, unsigned takes)
{
    bitset<99> nf;
    unsigned count(0), fortuity, i(0);
    vector<unsigned> bin(takes);
    
    if (pool > 99)
    {
        cout << "Pool overflow.";
        exit (EXIT_FAILURE);
    }
    
    nf.reset();
    
    while (nf.count() < takes)
    {
        do fortuity = rand() % (pool); while (nf[fortuity]);
        nf[fortuity] = true;        // mark it as drawn
    }
    for (; count < takes; )
    {
        if (nf[i++]) bin[count++] = i;
    }
    return bin;
}

int main()
{
    vector<unsigned> winners;
    unsigned pool(49), takes(6);
    srand (time(NULL));             // haphazardly seed

    winners = Lotto(pool, takes);
    cout << "Ziehung vom Mittwoch, 19.06.2019:";
    for (unsigned i = 0; i < takes; ++i)
    cout << "  " << winners[i];
    cout << '\n';
    cout << "Diese Angabe erfolgt wie immer ohne Gewähr.";
}

Ziehung vom Mittwoch, 19.06.2019:  4  11  20  23  38  41
Diese Angabe erfolgt wie immer ohne Gewähr.
Topic archived. No new replies allowed.