dice game vectors

I have a dice game where the user inputs a number from 1 to 10000 in the random generator and rolls 5 "dice". I have everything done up to that point. Now for the last part of the code I need to write a function that outputs a report of the best multiple value combination (5 of a kind, 4 of a kind, full house (3 of a kind of one value and 2 of a kind of another), 3 of a kind, two pair (two different 2 of a kind), 2 of a kind, a long straight (5 values in a row), a short straight (4 values in a row) or nothing) along with which dice value gave that combination; ex., 3 of a kind with 6s

I think you can do this through one function but I can't figure it out. Here is what I have so far
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
#include <iostream>
#include <vector>
#include <cstdlib>

void seedRNG();
int rollDie();
void rollAndReport();

int main()
{
    seedRNG();
    rollAndReport();

    system("PAUSE");
    return EXIT_SUCCESS;

}

void rollAndReport()
{
    std::vector<unsigned> frequency(7); 

    std::cout << "The rolled dice: ";
    for (unsigned i = 0; i < 5; ++i)
    {
        int roll = rollDie();
        std::cout << '[' << roll << "] ";
        ++frequency[roll];
    }

    std::cout << "\nThe frequencies: ";

    for (unsigned i = 1; i < frequency.size(); ++i)
        std::cout << i << " -> " << frequency[i] << "  ";
    std::cout << '\n';
}

void seedRNG()
{
    int seed;
    std::cout << "Enter an integer between 1 and 10000: ";
    std::cin >> seed;
    srand(seed);
}

int rollDie()
{
    return (rand() % 6) + 1;
}
Hello,

Would you like to have a random number? If not the user can keep inputing the same value over and over and it will yield the same result.

Simply do this to change that.
1
2
3
4
void seedRNG()
{
    srand(time(nullptr));
}


Can you please reword the OP I don't properly understand it. Sorry.
@Avilius I'm still going to use the user inputted numbers because that is the specifications for what my assignment calls for.

I want the output to look as such:

Enter seed (1 - 10,000): 27
Using seed of 27
The rolled dice: [1] [3] [3] [5] [5]
The frequencies: [1] [0] [2] [0] [2] [0]
The dice totaled 17
Two pair with 5s and 3s


I believe I could do this with perhaps a for loop and if statement. But I'm not sure how I would start that and set it up. Any ideas?
1
2
3
    for (unsigned i = 1; i < frequency.size(); ++i)
        std::cout << i << " -> " << frequency[i] << "  ";
    std::cout << '\n';
You're going to get undefined behavior here.

The dice is has 7 elements, you only use 5. The two integers are going to be of unknown value.

Try:
1
2
3
4
5
6
7
8
9
    frequency(6);

    std::cout << "The rolled dice: ";
    for (unsigned i = 0; i < 6; ++i)
    {
        int roll = rollDie();
        std::cout << '[' << roll << "] ";
        ++frequency[roll];
    }


---------------------

You should add a function that takes the 6 dice that are rolled's values and add them together.

1
2
3
4
int Adder(int val, int val1, int val2, int val3, int val4, int val5)
{
    return(val + val1 + val2 + val3 + val4 + val5);
}


For the last line of output just create a function that checks if a number has the same value as another.
Last edited on
How would you check for repeating values in a vector?
How would I make a for loop or if statement to accomplish the last part of the output?
Topic archived. No new replies allowed.