randomize symbols in slot machine game

In this assignment you will create a slot machine emulator. This slot machine will cost 1 credit to play and pay out 5 credits for each line you win on. It generates symbols from a pool of 10 different symbols and scrolls them on three different rollers – each displaying three symbols.

My code so far. I'm stuck on how to make the symbols randomly generate and also how to make it so if the user gets 3 of the same symbols horizontally/vertically/ or diagonally it rewards the user with 5 credits.
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
int name;
    int credits = 50;
    int letter;
    int randomNumber;
    
    
    cout <<"tttTHE BLUES SLOT MACHINE GAME!"<< endl;
    cout <<"Please enter your name:"<<endl;
    cin >> name;
    
    system("CLS");
    
    //symbols 
    char symbol = 31;
    char symbol1 = 30;
    char symbol2 = 16;
    char symbol3 = 17;
    char symbol4 = 3;
    char symbol5 = 2;
    char symbol6 = 1;
    char symbol7 = 22;
    char symbol8 = 15;
    char symbol9 = 19;
    
    
    cout <<"tttTHE BLUES SLOT MACHINE GAME!"<< endl;
    cout << "Credits:" << credits << endl; 
    cout << "--------------------------------------------------------------------------------nnn" ;
    
    //symbols
   
    
    cout << symbol << symbol1 << symbol2 << endl;
    cout << symbol3 << symbol4 << symbol5 << endl;
    cout << symbol6 << symbol7 << symbol8 << endl;
Last edited on
Non-Ambigious Hint: IF symbols 3, 4 AND 5 match THEN the user wins 5 credits. Think on the bolded portions of the sentence above, let us know if you need more.
Yes, but than how would I make it randomize?
This should be good enough for a school assignment: http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
and
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/


A guy on this site wrote a much better Randomizer and if I can find it I will link it here for you. But using it a school assignment at your apparent level would raise too many questions.
How do I make it so it re-rolls the slot machine after the user enters a key??
Try using a loop.
Try that code. It's simple but works and shows stuff pretty clear. rand() randoms a number but is every time the same. You should first do srand which is found in
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/

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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h>

using namespace std;

int main (){
    int name;
    char symbols[3][4] ={{0,0,0,12},
                         {0,0,0,12}, // 12 means a new line.
                         {0,0,0,12}};;
    int credits = 50;
    int letter;
    int randomNumber;    
    
    cout <<"tttTHE BLUES SLOT MACHINE GAME!"<< endl;
    cout <<"Please enter your name:"<<endl;
    cin >> name;
    
    system("CLS");
    
    char symbol = 31;
    char symbol1 = 30;
    char symbol2 = 16;
    char symbol3 = 17;
    char symbol4 = 3;
    char symbol5 = 2;
    char symbol6 = 1;
    char symbol7 = 22;
    char symbol8 = 15;
    char symbol9 = 19;
    
    cout <<"tttTHE BLUES SLOT MACHINE GAME!"<< endl;
    cout << "Credits:" << credits << endl; 
    cout << "--------------------------------------------------------------------------------n" ;   
   
    while(getch() != 27 && credits > 0){ // 27 is esc
    
    credits--;
    cout << endl << "Credits: " << credits;
        cout << endl << endl; 
    
          for(int i = 0; i<3; i++){
                  for(int j = 0; j<4; j++){
                          
                              int a = rand()%10+1; // defines which symbol
                              
                              if(symbols[i][j] != 12){
                              switch(a){
                                   case 1:
                                        symbols[i][j] = symbol;
                                        break;                                    
                                   case 2:
                                        symbols[i][j] = symbol1;
                                        break;                                        
                                   case 3:
                                        symbols[i][j] = symbol2;
                                        break;                                        
                                   case 4:
                                        symbols[i][j] = symbol3;
                                        break;                                        
                                   case 5:
                                        symbols[i][j] = symbol4;
                                        break;
                                   case 6:
                                        symbols[i][j] = symbol5;
                                        break;
                                   case 7:
                                        symbols[i][j] = symbol6;
                                        break;
                                   case 8:
                                        symbols[i][j] = symbol7;
                                        break;
                                   case 9:
                                        symbols[i][j] = symbol8;
                                        break;
                                   case 10:
                                        symbols[i][j] = symbol9;
                                        break;
                                        }
                                   }
                                        
                                   if(symbols[i][j] == 12){
                                       cout << "n";}else if(symbols[i][j] != 13){
                                        
                                   cout << symbols[i][j] << " ";
                                   }
                                   
                                   
                                  
                                   }
                          }   
                          if(symbols[1][0] == symbols[1][1] && // if all symbols in 
                                   symbols[1][0] == symbols[1][2]){ // middle are the same
                                         cout << "You won!n";
                                         credits += 5; // or something like 
                                         //credits += (int)symbols[1][0];   
                                         // so u win more for different symbols.
                                         // do something unbelievable...
                                                             
                  }
                   
    }
    
    system("pause");
return 0;
}


Good luck!
Topic archived. No new replies allowed.