Your opinion

I have been working on this for a while now and its about done, but I just want to make sure this is the best way of doing this.

Its a dice-game program rolling the dice x times, giving a random number between 1 and 6 and adding them together as well as showing the highest and lowest number.

The idea is to make it as flexible as possible, and preparing it to be devided into seperate files in the future.

Please give me your input on how to improve the flexibility and preperation.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

class Dice
{
    private:
        static const int TIMES = 10;
        int              game[TIMES];

    public:
        void roll();
        void result();
        void highDot();
        void lowDot();
        void enumerateDot();


};

int main()
{
    Dice user;

    user.roll();

    user.result();

    user.highDot();

    user.lowDot();

    user.enumerateDot();

    cout << "\n\nPress ENTER to exit.";
    cin.get();
}

//FUNCTIONS

void Dice::roll()
{
    srand(time(0)+rand());

    for(int i=0; i<Dice::TIMES; i++)
    {
        int dots=rand()%6+1;
        Dice::game[i]=dots;
    }
}

void Dice::result()
{
    cout << "Tossing the dice " << Dice::TIMES << " times gives you:\n" << endl;

    for(int i=0; i<Dice::TIMES; i++)
    {
        cout << Dice::game[i] << " ";
    }

    cout << "\n\n\n";
}

void Dice::highDot()
{
    int highest_number(0);

    for(int i=0; i<Dice::TIMES; i++)
    {
        if(Dice::game[i]>highest_number)
        {
            highest_number = Dice::game[i];
        }
    }

    cout << "\nMaximum number of dots is:\t" << highest_number << endl;
}

void Dice::lowDot()
{
    int lowest_number(6);

    for(int i=0; i<Dice::TIMES; i++)
    {
        if(Dice::game[i]<lowest_number)
        {
            lowest_number = Dice::game[i];
        }
    }

    cout << "Minimum number of dots is:\t" << lowest_number << endl;
}

void Dice::enumerateDot()
{
    int all_dots(0);

    for(int i=0; i<Dice::TIMES; i++)
    {
        all_dots+=Dice::game[i];
    }

    cout << "\nTotal number of dots is:\t" << all_dots << endl;
}


Thank you for your time!
Make roll method take an int: number of dices to be rolled.
Use dynamic arrays (or vector) to store any numbers of roll.
Support of different sided dices (d4, d6, d8, d10, 1d2 ,d20, d100...) is a godd idea.
that about flexibility.

You should use random generator classes in <random> and seed them once per instance of Dice, preferrably in constructor.

srand(time(0)+rand()); does not give you more randomness than just srand(time(0));.

Also you can calculat Low and High dot in roll method and store them in private variable, making highDot and LowDot an accessor functions.
Topic archived. No new replies allowed.