Let's Make A Slot Machine

The question at the end of chapter was:
Make a "slot machine" game that randomly displays the results of a slot machine to a player—have 3
(or more) possible values for each wheel of the slot machine. Don't worry about displaying the text
"spinning" by. Just choose the results and display them and print out the winnings (choose your own
winning combinations).


I did this:

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
  #include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int randRange(int high, int low);


int main()
{
    srand(time(NULL));
    int random_num = randRange(10, 1);      // first_ random number
    int random_num1 = randRange(10, 1);     // second random number

    cout << "Please Enter to run the slot machine" << endl;
    cin.get();

    if(random_num == random_num1)
    {
        cout << "The Numbers are " << random_num << " and " << random_num1 << ", you win" << endl;
    }
    else
    {
        cout << "The Numbers are " << random_num << " and " << random_num1 << ", you loose" << endl;
    }


}



int randRange(int high, int low)
{
    return rand() % (high - low) + low;
}


Is it good enough for a slot machine?

Please Share Your methods also , How will you make Slot Machine?
Last edited on
I guess this topic must be in the lounge since this is not a programming help or issue. It's likely that you'll find positive responses there.
Can you move it there ?
Click EDIT option of this topic and change the section from beginner to Lounge.
So, there are only two slots?
closed account (1v5E3TCk)
When I came to that exercise I code it like that:

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
#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;

int sayi(int alt, int ust)
{
    return rand()%(ust-alt)+alt;
}

int main()
{
    int x,y,z;

    srand (time(NULL));

    while(1)
    {
        x=sayi(1,4);
        y=sayi(1,4);
        z=sayi(1,4);

        cout<<"|---|---|---|\n";
        cout<<"| "<<x<<" | "<<y<<" | "<<z<<" |\n";
        cout<<"|---|---|---|\n";

        if(x==y&&y==z)
            {
                cout<<"Kazandiniz.";
            }

        else
            {
                cout<<"Kaybettiniz.";
            }
        cin.get();
    }
}


Note: Press ENTER to run.

Kaybettiniz = you lose
Kazandınız = You won


EDIT: Organized code
Last edited on
Isn't a slot machine one where you have fruit or whatever and you have to line up 3 of them to win?
I know what a slot machine is. How will you code what you just said?
If was doing it with graphics, I definitely use a game engine. If I was doing it in the console, I'd do it with <string> using 3 string arrays holding each fruit.
1
2
3
4
string slot1[10], slot2[10], slot3[10]; 
//Then fill the slots
//Then generate random mixes of them. 
//Then check if 3 are lined up and give the appropriate prize (i.e. the same fruit was chosen on all 3). 
Last edited on
Nice!
Topic archived. No new replies allowed.