Random Numbers help

I am currently writing a slot game program. I have most of it worked out but I cant seem to generate random numbers. In the spinner function I call another function called display which shows 1 of 3 different picture depending on number given to it. However, this is not the case. The same picture is displayed every time for all three calls to the function. I am not sure where I am going wrong any helps in making this work that would be awesome.

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>

using namespace std;

class slots
{
    public:
    slots();
    inline void cls();
    inline void stop();
    inline void red();
    inline void green();
    inline void pink();
    void spinner();
    int amount_won(int wagger);
    int ask_bet(string prompt);
    int random_num_range(int high, int low);
    int m_bet;
    bool winner(int a, int b, int c);
    bool welcome();
    void display(int c);
};

slots::slots()
{};

inline void slots::cls(){system("cls");}

inline void slots::stop(){system("pause");}

inline void slots::red() {system("color 0C");}

inline void slots::green() {system("color 03");}

inline void slots::pink() {system("color 0D");}

bool slots::welcome()
{
    cls();
    string answer;
    cout<<" Welcome to the slot game!!\n\n";
    cout<<" Would you like to play? (y/n)";
    cin>>answer;
    if(answer == "y")
    {
        return true;
    }
    else
    {
        return false;
    }

}


void slots::display(int c)
{

    if(c == 1)
    {
        cout<<"          .:'      "<<endl;
        cout<<"      __ :'__      "<<endl;
        cout<<"   .'`  `-'  ``.   "<<endl;
        cout<<"  :            :   "<<endl;
        cout<<"  :            :   "<<endl;
        cout<<"  :           :    "<<endl;
        cout<<"   `.__.-.__.'     "<<endl;
    }
    else if (c == 2)
    {
        cout<<"       )          "<<endl;
        cout<<"      C,          "<<endl;
        cout<<"     ( ~)         "<<endl;
        cout<<"     ( ~)         "<<endl;
        cout<<"     (~ )         "<<endl;
        cout<<"     \\~~/         "<<endl;
        cout<<"      \\/          "<<endl;
    }
     else if ( c == 3 )
     {
        cout<<"  __________    '.  :  .'  "<<endl;
        cout<<" /         /\\__.__'.:.'  . "<<endl;
        cout<<" \\_________\\/  .  .':'.  . "<<endl;
        cout<<"                .'  :  '.  "<<endl;
     }


    }



void slots::spinner()
{

    int a,b,c;

    for(int j =0; j<25; j++)
    {
         a = random_num_range(1,3);
         b = random_num_range(1,3);
         c = random_num_range(1,3);

     if(j>20)
     {
         red();
     }
     else if(j>5)
     {
         green();
     }
     //cout<<a<<" || "<<b<<" || "<<c<<endl;
     display(a); display(b); display(c);
     //cout<<"   ";
     //display(b);
     //cout<<"   ";
     //display(c);

    Sleep(500);
    cls();
    }
    bool win_loss = winner(a, b, c);
    if(win_loss == true)
    {
        int pay_out = amount_won(m_bet);
        cout<<" Jack Pot You Won! "<<pay_out<<"\n\n\n\n";
        stop();
    }
    else
    {
        cout<<" you lose!\n\n\n\n\n";
        stop();
    }

}

int slots::random_num_range(int high, int low)
{
    return rand() %(high - low +1) + low;
}

bool slots::winner(int a, int b, int c)
{
    if(a == b && b == c)
    {
        return true;
    }
    else if(a == c)
    {
        return true;
    }
    else if(c == b)
    {
        return true;
    }
    else{return false;}
}

int slots::amount_won(int wagger)
{
    return wagger*3;
}

int slots::ask_bet(string prompt)
{
    int bet;
    cout<<prompt;
    cin>>bet;
    m_bet = bet;
}

int main()
{

    srand(time(NULL));
    slots player;// creating the the player
    string answer;
    bool play = player.welcome();
    while(play != false)
    {
        player.ask_bet("How much do you want to wagger?");
        player.spinner();
        player.cls();
        cout<<"Would you like to play again?";
        cin>>answer;
        if(answer == "Y")
        {
            play = true;
            continue;
        }
        else
        {
            play == false;
            break;
        }
    }

   cout<<"Good Bye!";


    return 0;
}
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
#include <iostream>
#include <random>
#include <ctime>

constexpr std::size_t NPICS = 3 ;

void display( unsigned int c )
{
    static const char* const pictures[NPICS] =
    {
        "          .:'      \n"
        "      __ :'__      \n"
        "   .'`  `-'  ``.   \n"
        "  :            :   \n"
        "  :            :   \n"
        "  :           :    \n"
        "   `.__.-.__.'     \n",

        "       )          \n"
        "      C,          \n"
        "     ( ~)         \n"
        "     ( ~)         \n"
        "     (~ )         \n"
        "     \\~~/         \n"
        "      \\/          \n",

        "  __________    '.  :  .'  \n"
        " /         /\\__.__'.:.'  . \n"
        " \\_________\\/  .  .':'.  . \n"
        "                .'  :  '.  \n"
     };


     std::cout << pictures[ c % NPICS ] ;
}

void spinner()
{
    // http://en.cppreference.com/w/cpp/numeric/random
    static std::mt19937 rng( std::time(nullptr) ) ;
    static std::uniform_int_distribution<int> random_colour( 0, 1 ) ;
    static const char* const colours[] = { "RED", "GREEN" } ;
    std::cout << "set colour " << colours[ random_colour(rng) ]  << '\n' ;

    static std::uniform_int_distribution<int> random_picture( 0, NPICS ) ;
    display( random_picture(rng) ) ;
    std::cout << "------------------------------\n" ;
}

int main()
{
    for( int i = 0 ; i < 8 ; ++i ) spinner() ;
}

http://coliru.stacked-crooked.com/a/88066fab94ede7b0
Topic archived. No new replies allowed.