[try Beta version]
Not logged in

 
Slot machine help?

Jun 15, 2013 at 5:03pm
I am making a program that emulates a slot machine. I have three functions, each of which represent one of the three reels. Each function vertically displays a three symbol sequence of the reel. How do I place each function side by side so that I get a 3 x 3 grid of the slot machine's values?

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

using namespace std;

//Value between 1-20, random
// Each value represents a three symbol sequence on a reel
int LeftReel ()
{
    return rand() % 21;
}

void LeftReelSymbol()
{
    switch (LeftReel())
    {
    case 1:
        cout << "Bell " << '\n' << '\n' << "Orange " << '\n' << '\n' << "Blueberry "<< '\n';
        break;
    case 2:
        cout << "Orange " << '\n' << '\n' << "Blueberry " << '\n' << '\n' << "Bell "<< '\n';
        break;
    case 3:
        cout << "Blueberry " << '\n' << '\n' << "Bell " << '\n' << '\n' << "Orange "<< '\n';
        break;
    case 4:
        cout << "Bell " << '\n' << '\n' << "Orange " << '\n' << '\n' << "Lemon "<< '\n';
        break;
    case 5:
        //Continues like this for all values between 1-20

    }
}

int MiddleReel ()
{
    return rand() % 21;

}

void MiddleReelSymbol()
{
    //Same as LeftReelSymbol(), but different sequences
}


int RightReel ()
{
    return rand() % 21;
}

void RightReelSymbol()
{
    //Same as LeftReelSymbol(), but different sequences
}

int main()
{

    srand(time(NULL));

    cout << "Slot machine!" << '\n' << '\n';
//Here in the program, all of the functions display their outputs
//But instead of being lined up like a typical slot machine, 
//It just ends up looking a list
    LeftReelSymbol();
    MiddleReelSymbol();
    RightReelSymbol();


}
}
Last edited on Jun 15, 2013 at 10:15pm
Jun 15, 2013 at 5:42pm
You have two options.

1) Put all the output into a string buffer and print the buffer all at the same time.

2) Use a console control program to allow you to define sub-windows in the console window and/or position the cursor in the window and write stuff there.

It looks like all you really need to do, though, is adjust your print width with something like:

 
    const char* symbol[] = { "Apple", "Banana", "Orange", "Bar", etc };
1
2
3
4
5
6
7
8
9
10
    int left_reel = LeftReel();
    int middle_reel = MiddleReel();
    int right_reel = RightReel();

    for (int n = -1; n < 2; n++)
    {
        cout << setw( 26 ) << left << Symbol[ left_reel   + n ] << flush;
        cout << setw( 26 ) << left << Symbol[ middle_reel + n ] << flush;
        cout << setw( 26 ) << left << Symbol[ right_reel  + n ] << endl;
    }

Hope this helps.
Jun 15, 2013 at 6:27pm
So I did this:

 
cout << setw( 26 ) << left << LeftReelSymbol() << endl;


And this error popped up:

"no match for 'operator<<' in '(& std::operator<< <char, std::char_traits<char> ..."

Sorry, this setw thing is something I haven't learned about yet
Jun 15, 2013 at 6:34pm
to use setw(#) you need to include the library #include <iomanip>
Jun 15, 2013 at 6:38pm
Yes, I did that. These are all the things at the top of my program:

1
2
3
4
5
6
# include <ctime>
# include <cstdlib>
# include <iostream>
# include <iomanip>

using namespace std;
Jun 16, 2013 at 6:01am
LeftReelSymbol() doesn't return anything; it is a void function.

[edit]And you can't print something that doesn't exist.
Last edited on Jun 16, 2013 at 6:02am
Jun 16, 2013 at 6:05am
You should put the setw in the leftreelsymbol function or have the function return a string of what you want to output.
Jun 17, 2013 at 12:25am
I got setw to work, but all it does is indent the the left reel. The other reels still don't line up.
Last edited on Jun 20, 2013 at 1:19am
Jun 20, 2013 at 1:21am
Bump
Topic archived. No new replies allowed.