Thread: Slot machine, payout randomize.

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    10

    Slot machine, payout randomize.

    Hello everyone! I'm new to the forums. I've searched Google to no end, and I'm at a loss at what to do. I usually try to figure things out on my own, but I'm just struggling something fierce so I come asking for help.

    I'm working on a slot machine. There needs to be a three wheel & four wheel machine option. I'm working on two different concepts to receive the same output for each wheel (beats having several copies of the same console).

    I cannot figure out how to do the if/else if/else statement for the random payout options. I can do it just fine if I use JUST numbers, but since I am forced to use the output of words (star, star, star - etc.), I'm just at a standstill on how to proceed.

    In this code, I'm currently working under the void four() function, and everything is far from perfect. Trust me, I know that. In this function, it only prints out BAR - BAR - BAR. As you can see, listed in the payout table... that's the outputs I need. I just don't know how to proceed. I've tried arrays. I've tried switch statements. I've tried enumerations (and got absolutely nowhere with that).

    Pretty sure there's something I'm overlooking and it's so stinkin' simple. But right now, I'm just fried and desperate. Everything I've seen on other forums is for a 3x3 grid and I don't need that. Just simple 3x anything, 2x + 1 of anything, and straight up loser.

    Any help would be appreciated. (As an aside, I posted this on DaniWeb a few days ago - I don't know the protocol for cross posting).

    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <ctime>
    #include <cstdlib>
    
    using namespace std;
    
    int credits = 50;
    int bet = 0;
    string slotLabels; // fruit names
    int slotFruits; // fruits
    string wheel1;
    string wheel2;
    string wheel3;
    
    void menu(char decision);
    void earnings();
    void three(); // for three wheel slot machine.
    void four(); // for four wheel slot machine.
    
    int main()
    {
        srand(unsigned(time(NULL)));
    
        char pay = 0;
        char decision;
    
        cout << "WELCOME TO THE BOOGIE DOWN SLOT MACHINE!\n\n";
        cout << "'3' - start the three wheel slot machine.\n"
                "'4' - start the four wheel slot machine.\n"
                "'T' - access the pay table.\n"
                "'P' - collect your earnings & cash out.\n"
                "'Q' - quit the game.\n" << endl;
    
        cout << "Let's play! What would you like to do? ";
        cin >> decision;
    
        cout << endl;
        cout << endl;
    
        menu(decision);
    
        return 0;
    
    }
    
    // FUNCTION FOR THE MAIN MENU DECISIONS //
    void menu(char decision)
    {
        // DECISION FOR THE TABLE PAYOUT ("T") //
        if (decision == 'T')
        {
            cout << "THREE WHEEL SLOT MACHINE:    FOUR WHEEL SLOT MACHINE:            PAYOUT:\n";
            cout << "STAR - STAR - STAR           STAR - STAR - STAR - STAR           1,000 COINS\n";
            cout << "BAR - BAR - BAR              BAR - BAR - BAR - BAR               500 COINS\n";
            cout << "SEVEN - SEVEN - SEVEN        SEVEN - SEVEN - SEVEN - SEVEN       250 COINS\n";
            cout << "BAR - BAR - ANY              BAR - BAR - BAR - ANY               100 COINS\n";
            cout << "PLUM - PLUM - PLUM           PLUM - PLUM - PLUM - PLUM           75 COINS\n";
            cout << "LEMON - LEMON - LEMON        LEMON - LEMON - LEMON - LEMON       50 COINS\n";
            cout << "CHERRY - CHERRY - ANY        CHERRY - CHERRY - ANY - ANY         25 COINS\n";
            cout << "CHERRY - ANY - ANY           CHERRY - ANY - ANY - ANY            5 COINS\n" << endl;
        }
    
        // DECISION TO START THE THREE WHEEL SLOT MACHINE ("3") //
        if (decision == '3')
        {
            three();
        }
    
        // DECISION TO START THE FOUR WHEEL SLOT MACHINE ("4") //
        if (decision == '4')
        {
            four();
        }
    
        // DECISION TO CASH OUT CREDITS //
        if (decision == 'P')
        {
            if (credits > 0)
            {
                cout << "You've cashed out " << credits << "!" << endl;
                credits = 0;
            }
    
        menu(decision);
        }
    }
    
    // FUNCTION TO START THE THREE WHEEL SLOT MACHINE //
    void three()
    {
        int wheel1, wheel2, wheel3;
    
        wheel1 = (rand() % 6) + 1;
        wheel2 = (rand() % 6) + 1;
        wheel3 = (rand() % 6) + 1;
    
        cout << "You currently have " << credits << " credits." << endl;
        cout << "How many of those credits would you like to bet? ";
        cin >> bet;
        cout << endl;
    
        // switch statement for the first wheel
        switch (wheel1)
        {
        case 1:
            cout << "STAR -" << " ";
            break;
        case 2:
            cout << "BAR -" << " ";
            break;
        case 3:
            cout << "SEVEN -" << " ";
            break;
        case 4:
            cout << "PLUM -" << " ";
            break;
        case 5:
            cout << "LEMON -" << " ";
            break;
        case 6:
            cout << "CHERRY -" << " ";
            break;
        }
    
        // switch statement for the second wheel
    
        switch (wheel2)
        {
        case 1:
            cout << "STAR -" << " ";
            break;
        case 2:
            cout << "BAR -" << " ";
            break;
        case 3:
            cout << "SEVEN -" << " ";
            break;
        case 4:
            cout << "PLUM -" << " ";
            break;
        case 5:
            cout << "LEMON -" << " ";
            break;
        case 6:
            cout << "CHERRY -" << " ";
            break;
        }
    
        // switch statement for wheel three
        switch (wheel3)
        {
        case 1:
            cout << "STAR -" << " ";
            break;
        case 2:
            cout << "BAR -" << " ";
            break;
        case 3:
            cout << "SEVEN -" << " ";
            break;
        case 4:
            cout << "PLUM -" << " ";
            break;
        case 5:
            cout << "LEMON -" << " ";
            break;
        case 6:
            cout << "CHERRY -" << " ";
            break;
        }
    
        if (wheel1 == 1 && wheel2 == 1 && wheel3 == 1) // THREE STARS (1,000)
        {
            credits = credits - bet;
            cout << "JACKPOT! You won 1,000 credits." << endl;
            cout << "You currently have " << credits + 1000 << " credits." << endl;
        }
        else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2) // THREE BARS (500)
        {
            credits = credits - bet;
            cout << "AMAZING! You won 500 credits." << endl;
            cout << "You currently have " << credits + 500 << " credits." << endl;
        }
        else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2) // THREE SEVENS (250)
        {
            credits = credits - bet;
            cout << "AWESOME! You won 250 credits." << endl;
            cout << "You currently have " << credits + 250 << " credits." << endl;
        }
        else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 0) // TWO BARS & ANYTHING (100) - How do I get it to random one of the others?!
        {
            credits = credits - bet;
            cout << "NICE! You won 100 credits." << endl;
            cout << "You currently have " << credits + 100 << " credits." << endl;
        }
        else if (wheel1 == 4 && wheel2 == 4 && wheel3 == 4) // THREE PLUMS (75)
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 75 credits." << endl;
            cout << "You currently have " << credits + 75 << " credits." << endl;
        }
        else if (wheel1 == 5 && wheel2 == 5 && wheel3 == 5) // THREE LEMONS (50)
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 50 credits." << endl;
            cout << "You currently have " << credits + 50 << " credits." << endl;
        }
        else if (wheel1 == 6 && wheel2 == 6 && wheel3 == 0) // TWO CHERRIES & ANYTHING (25)
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 25 credits." << endl;
            cout << "You currently have " << credits + 25 << " credits." << endl;
        }
        else if (wheel1 == 6 && wheel2 == 0 && wheel3 == 0) // ONE CHERRY & TWO ANYTHING (5)
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 5 credits." << endl;
            cout << "You currently have " << credits + 5 << " credits." << endl;
        }
    }
    
    // FUNCTION TO START THE FOUR WHEEL SLOT MACHINE //
    void four()
    {
    
        int STAR = 1;
        int BAR = 2;
        int SEVEN = 3;
        int PLUM = 4;
        int LEMON = 5;
        int CHERRY = 6;
    
        int wheel1;
        int wheel2;
        int wheel3;
    
        cout << "You have " << credits << " credits." << endl;
        cout << "How much would you like to bet? ";
        cin >> bet;
        credits = credits - bet;
    
        wheel1 = (rand() % 6) + 1;
        wheel2 = (rand() % 6) + 1;
        wheel3 = (rand() % 6) + 1;
    
        if (wheel1 == wheel2 == wheel3)
        {
            cout << "STAR - STAR - STAR" << endl << endl;
            cout << "JACKPOT! You won 1,000 credits!." << endl;
            cout << "You currently have " << credits << " credits." << endl;
        }
        else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2)
        {
            cout << "BAR - BAR - BAR" << endl;
            cout << "You won, yay." << endl;
        }
        else if (wheel1 == 3 && wheel2 == 3 && wheel3 == 3)
        {
            cout << "SEVEN - SEVEN - SEVEN" << endl;
            cout << "You won, yay." << endl;
        }
        else if (wheel1 == 4 && wheel2 == 4 && wheel3 == 4)
        {
            cout << "PLUM - PLUM - PLUM" << endl;
            cout << "You won, yay." << endl;
        }
        else if (5 == LEMON)
        {
            cout << "BAR - BAR - BAR" << endl;
            cout << "You won, yay." << endl;
        }
        else if (6 == CHERRY)
        {
            cout << "BAR - BAR - BAR" << endl;
            cout << "You won, yay." << endl;
        }
        else
        {
            cout << "LOSER?";
        }
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I can do it just fine if I use JUST numbers, but since I am forced to use the output of words (star, star, star - etc.), I'm just at a standstill on how to proceed.
    Have you looked into using a vector of strings, with a vector for each "wheel"?


    Jim

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by jimblumberg View Post
    Have you looked into using a vector of strings, with a vector for each "wheel"?


    Jim
    Considering I have no idea what a vector is, I'm going to have to say no. I have used strings, however. I still come to the same problem of not knowing how to manipulate the payout.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Did you try Googling "C++ vector"? Or have you studied arrays yet?
    I still come to the same problem of not knowing how to manipulate the payout.
    I suggest you work on one problem at a time, first get the "wheels" to turn the worry about paying the "customer".

    Also consider more functions. You seem to have quite a bit of duplicate code. Lastly get rid of all those global variables. Learn to properly pass the variables to and from your functions as required.

    Jim

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    The only thing we've really done with arrays is storing a collection of values. Never really doing anything with them in this type of sense. I'll definitely google, though.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Here's an idea.

    Code:
        // switch statement for the first wheel
        switch (wheel1)
        {
        case 1:
            cout << "STAR -" << " ";
            break;
        case 2:
            cout << "BAR -" << " ";
            break;
        case 3:
            cout << "SEVEN -" << " ";
            break;
        case 4:
            cout << "PLUM -" << " ";
            break;
        case 5:
            cout << "LEMON -" << " ";
            break;
        case 6:
            cout << "CHERRY -" << " ";
            break;
        }
    Each wheel is going to be one of these case numbers. If you add each wheel together, you should have a sum that you would only get if you added those three results. That is what you base the payout on: if they hit a target sum, you owe 5, 25, 50 ... or 1,000 coins.

  7. #7
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by jimblumberg View Post
    Did you try Googling "C++ vector"? Or have you studied arrays yet?

    I suggest you work on one problem at a time, first get the "wheels" to turn the worry about paying the "customer".

    Also consider more functions. You seem to have quite a bit of duplicate code. Lastly get rid of all those global variables. Learn to properly pass the variables to and from your functions as required.

    Jim
    I'm not going to lie. I'm confused as all get out right now.

    My getting random output is getting the wheels to turn, right?

  8. #8
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by whiteflags View Post
    Here's an idea.

    Code:
        // switch statement for the first wheel
        switch (wheel1)
        {
        case 1:
            cout << "STAR -" << " ";
            break;
        case 2:
            cout << "BAR -" << " ";
            break;
        case 3:
            cout << "SEVEN -" << " ";
            break;
        case 4:
            cout << "PLUM -" << " ";
            break;
        case 5:
            cout << "LEMON -" << " ";
            break;
        case 6:
            cout << "CHERRY -" << " ";
            break;
        }
    Each wheel is going to be one of these case numbers. If you add each wheel together, you should have a sum that you would only get if you added those three results. That is what you base the payout on: if they hit a target sum, you owe 5, 25, 50 ... or 1,000 coins.
    So do I keep each wheel case statement? As in, do I keep wheel1, wheel2, and wheel3 - then just add them?
    Would it be something like wheel1 = 1, wheel2 = 1, wheel3 = 1; wheel1 + wheel2 + wheel3 = STAR STAR STAR?

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    It would be more like:

    slotsValueSum = wheel1 + wheel2 + wheel3;

    Then you have another, separate switch case statement. Each of the winning sums would be a separate case, and depending on which case matches the SlotsValueSum, you know how much or how little to pay out. You probably want a default case, to handle the times when people just loose at the slot machine.


    A second idea, if that one is too hard, is to fill an array with different strings:
    Code:
    string slotValues[] = {"STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY"...};
    The idea here would be to use random numbers select three or four times from an array like this one. The number of occurences of "STAR", "CHERRY", or whatever, out of all the values of the array determine the odds of that value being picked.

    The good thing about this is that you can use the array values you picked to form the output. And checking for a win condition is as easy as something like:
    Code:
    array[random1] == "STAR" && array[random2] == "STAR" && array[random3] == "STAR"

  10. #10
    Registered User MilleniumFalcon's Avatar
    Join Date
    Feb 2014
    Posts
    33
    Here is the method I would use to "spin the wheel":

    Code:
    enum
    {
        SPIN = 1,
        EXIT
    };
    
    
    enum
    {
        STAR,
        BAR,
        SEVEN,
        PLUM,
        LEMON,
        CHERRY,
    };
    
    
    const char * wheelType[] =
    {
        "STAR",
        "BAR",
        "SEVEN",
        "PLUM",
        "LEMON",
        "CHERRY"
    };
    
    
    bool Spin()
    {
        int wheel[3] = { 0 };
    
    
        for ( unsigned int i = 0; i < sizeof( wheel )/sizeof( *wheel ); ++i )
            wheel[i] = rand() % 6;
    
    
        cout << "Spin : " << wheel[0] << " " << wheel[1] << " " << wheel[2] << END;
    
    
        if ( ( wheel[0] == wheel[1] ) && ( wheel[1] == wheel[2] ) )
        {
            cout << wheelType[*wheel] << " - " << wheelType[*wheel] << " - " << wheelType[*wheel] << END;
    
    
            switch ( *wheel )
            {
                case STAR :
                    cout << "Jackpot" << END;
                break;
    
    
                default :
                    cout << "You have won!" << END;
                break;
            }
    
    
            return true;
        }
    
    
        cout << "Loser!" << END;
        return false;
    }
    I wrote the above code for you to use as an example. Notice how the name of the function is more intuitive than yours. Function naming is important so you can have your code resemble the problem you are trying to solve, and help others understand the logic you are following when using your code. It will also be easier if you come back to this code and update it, since you will be able to guess what "Spin()" does in that context. I used an array to strings to help build output for the user, similar to what WhiteFlags suggested. I simply had the numbers correspond to the index of the correct string. I also used enumerations and arrays to reduce the number of variables needed.
    Last edited by MilleniumFalcon; 04-06-2014 at 06:14 PM.

  11. #11
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by whiteflags View Post
    It would be more like:

    slotsValueSum = wheel1 + wheel2 + wheel3;

    Then you have another, separate switch case statement. Each of the winning sums would be a separate case, and depending on which case matches the SlotsValueSum, you know how much or how little to pay out. You probably want a default case, to handle the times when people just loose at the slot machine.


    A second idea, if that one is too hard, is to fill an array with different strings:
    Code:
    string slotValues[] = {"STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY"...};
    The idea here would be to use random numbers select three or four times from an array like this one. The number of occurences of "STAR", "CHERRY", or whatever, out of all the values of the array determine the odds of that value being picked.

    The good thing about this is that you can use the array values you picked to form the output. And checking for a win condition is as easy as something like:
    Code:
    array[random1] == "STAR" && array[random2] == "STAR" && array[random3] == "STAR"
    Ah, yes. I was just about to post with that I changed my code to using a string array. And then the only issue I was having with that was that I was receiving the error "IntelliSense: operand types are incompatible ("int" and "const char *")" for each of the == and !=, which made me believe I was going about reading the wheels incorrectly. Then I saw your comment, and I think I might know how to approach it now. Maybe.

    Code:
    void three()
    {
        int wheel1 = (rand() % 6) + 1;
        int wheel2 = (rand() % 6) + 1;
        int wheel3 = (rand() % 6) + 1;
    
        string fruitLabels[6] = {"STAR", "BAR", "SEVEN", "PLUM", "LEMON", "CHERRY"};
    
        cout << "You currently have " << credits << " credits." << endl;
        cout << "How many of those credits would you like to bet? ";
        cin >> bet;
        cout << endl;
    
        if (wheel1 == "STAR" && wheel2 == "STAR" && wheel3 == "STAR")
        {
            credits = credits - bet;
            cout << "JACKPOT! You won 1,000 credits." << endl;
            cout << "You currently have " << credits + 1000 << " credits." << endl;
        }
        else if (wheel1 == "BAR" && wheel2 == "BAR" && wheel3 == "BAR")
        {
            credits = credits - bet;
            cout << "AMAZING! You won 500 credits." << endl;
            cout << "You currently have " << credits + 500 << " credits." << endl;
        }
        else if (wheel1 == "SEVEN" && wheel2 == "SEVEN" && wheel3 == "SEVEN")
        {
            credits = credits - bet;
            cout << "AWESOME! You won 250 credits." << endl;
            cout << "You currently have " << credits + 250 << " credits." << endl;
        }
        else if (wheel1 == "PLUM" && wheel2 == "PLUM" && wheel3 == "PLUM")
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 75 credits." << endl;
            cout << "You currently have " << credits + 75 << " credits." << endl;
        }
        else if (wheel1 == "BAR" && wheel2 == "BAR" && wheel3 != "BAR")
        {
            credits = credits - bet;
            cout << "NICE! You won 100 credits." << endl;
            cout << "You currently have " << credits + 100 << " credits." << endl;
        }
        else if (wheel1 == "LEMON" && wheel2 == "LEMON" && wheel3 == "LEMON")
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 50 credits." << endl;
            cout << "You currently have " << credits + 50 << " credits." << endl;
        }
        else if (wheel1 == "CHERRY" && wheel2 == "CHERRY" && wheel3 != "CHERRY")
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 25 credits." << endl;
            cout << "You currently have " << credits + 25 << " credits." << endl;
        }
        else if (wheel1 == "CHERRY" && wheel2 != "CHERRY" && wheel3 != "CHERRY")
        {
            credits = credits - bet;
            cout << "GOOD JOB! You won 5 credits." << endl;
            cout << "You currently have " << credits + 5 << " credits." << endl;
        }
        else ("YOU LOST!");
    }
    And I completely get what you were saying about the sum of the wheels, but my mind is like "math?" Hah. I might give it a try, though, since I'm always willing to try different approaches (currently, though, going to try to get this done the best way I can since it's due next week).

  12. #12
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by MilleniumFalcon View Post
    Here is the method I would use to "spin the wheel":

    Code:
    enum
    {
        SPIN = 1,
        EXIT
    };
    
    
    enum
    {
        STAR,
        BAR,
        SEVEN,
        PLUM,
        LEMON,
        CHERRY,
    };
    
    
    const char * wheelType[] =
    {
        "STAR",
        "BAR",
        "SEVEN",
        "PLUM",
        "LEMON",
        "CHERRY"
    };
    
    
    bool Spin()
    {
        int wheel[3] = { 0 };
    
    
        for ( unsigned int i = 0; i < sizeof( wheel )/sizeof( *wheel ); ++i )
            wheel[i] = rand() % 6;
    
    
        cout << "Spin : " << wheel[0] << " " << wheel[1] << " " << wheel[2] << END;
    
    
        if ( ( wheel[0] == wheel[1] ) && ( wheel[1] == wheel[2] ) )
        {
            cout << wheelType[*wheel] << " - " << wheelType[*wheel] << " - " << wheelType[*wheel] << END;
    
    
            switch ( *wheel )
            {
                case STAR :
                    cout << "Jackpot" << END;
                break;
    
    
                default :
                    cout << "You have won!" << END;
                break;
            }
    
    
            return true;
        }
    
    
        cout << "Loser!" << END;
        return false;
    }
    I wrote the above code for you to use as an example. Notice how the name of the function is more intuitive than yours. Function naming is important so you can have your code resemble the problem you are trying to solve, and help others understand the logic you are following when using your code. It will also be easier if you come back to this code and update it, since you will be able to guess what "Spin()" does in that context. I used an array to strings to help build output for the user, similar to what WhiteFlags suggested. I simply had the numbers correspond to the index of the correct string. I also used enumerations and arrays to reduce the number of variables needed.
    I've used something very similar to this ex. that you gave. However, just like you, I can get it to work with numbers. I just can't get it to print out the words.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MilleniumFalcon View Post
    Here is the method I would use to "spin the wheel":
    You are abusing enums. They are not meant to be constants. You are meant to use them as a way of limiting valid values for a variable, which you are not.
    While we're on the subject, please look up type-safe enums (i.e. enum class).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by Elysia View Post
    You are abusing enums. They are not meant to be constants. You are meant to use them as a way of limiting valid values for a variable, which you are not.
    While we're on the subject, please look up type-safe enums (i.e. enum class).
    I haven't worked much with enums and even I thought that looked a little off.

  15. #15
    Registered User
    Join Date
    Apr 2014
    Posts
    10
    Quote Originally Posted by whiteflags View Post
    A second idea, if that one is too hard, is to fill an array with different strings:
    Code:
    string slotValues[] = {"STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "STAR", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY", "CHERRY"...};
    The idea here would be to use random numbers select three or four times from an array like this one. The number of occurences of "STAR", "CHERRY", or whatever, out of all the values of the array determine the odds of that value being picked.

    The good thing about this is that you can use the array values you picked to form the output. And checking for a win condition is as easy as something like:
    Code:
    array[random1] == "STAR" && array[random2] == "STAR" && array[random3] == "STAR"
    AH HA! I'm on to something. Now the only issue I have is the printing out of each wheel spin (ex. STAR STAR STAR, etc.) I know how to do 3x of something, but the 2x + anything else is stumping me and also the loss (ex: LEMON BAR SEVEN). Here's what's totally working for me right now (minus the printing what I need it to):

    Code:
       int wheel1 = (rand() % 6) + 1;
        int wheel2 = (rand() % 6) + 1;
        int wheel3 = (rand() % 6) + 1;
    
        string fruitLabels[] = {"STAR", "BAR", "SEVEN", "PLUM", "LEMON", "CHERRY"};
    
        cout << "You currently have " << credits << " credits." << endl;
        cout << "How many of those credits would you like to bet? ";
        cin >> bet;
        cout << endl;
    
        if (fruitLabels[wheel1] == "STAR" && fruitLabels[wheel2] == "STAR" && fruitLabels[wheel3] == "STAR")
        {
            credits = credits - bet;
            cout << "STAR - STAR - STAR" << endl;
            cout << "JACKPOT! You won 1,000 credits." << endl;
            cout << "You currently have " << credits + 1000 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "BAR" && fruitLabels[wheel2] == "BAR" && fruitLabels[wheel3] == "BAR")
        {
            credits = credits - bet;
            cout << "BAR - BAR - BAR" << endl;
            cout << "AMAZING! You won 500 credits." << endl;
            cout << "You currently have " << credits + 500 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "SEVEN" && fruitLabels[wheel2] == "SEVEN" && fruitLabels[wheel3] == "SEVEN")
        {
            credits = credits - bet;
            cout << "SEVEN - SEVEN - SEVEN" << endl;
            cout << "AWESOME! You won 250 credits." << endl;
            cout << "You currently have " << credits + 250 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "PLUM" && fruitLabels[wheel2] == "PLUM" && fruitLabels[wheel3] == "PLUM")
        {
            credits = credits - bet;
            cout << "PLUM - PLUM - PLUM" << endl;
            cout << "GOOD JOB! You won 75 credits." << endl;
            cout << "You currently have " << credits + 75 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "BAR" && fruitLabels[wheel2] == "BAR" && fruitLabels[wheel3] != "BAR")
        {
            credits = credits - bet;
            cout << "BAR - BAR - ANYTHING ELSE" << endl; // see, this needs to be BAR BAR + let's say LEMON
            cout << "NICE! You won 100 credits." << endl;
            cout << "You currently have " << credits + 100 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "LEMON" && fruitLabels[wheel2] == "LEMON" && fruitLabels[wheel3] == "LEMON")
        {
            credits = credits - bet;
            cout << "LEMON - LEMON - LEMON" << endl;
            cout << "GOOD JOB! You won 50 credits." << endl;
            cout << "You currently have " << credits + 50 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "CHERRY" && fruitLabels[wheel2] == "CHERRY" && fruitLabels[wheel3] != "CHERRY")
        {
            credits = credits - bet;
            cout << "CHERRY - CHERRY - ANYTHING" << endl; // here, too... also, it doesn't have to be in this order either
            cout << "GOOD JOB! You won 25 credits." << endl;
            cout << "You currently have " << credits + 25 << " credits." << endl;
        }
        else if (fruitLabels[wheel1] == "CHERRY" && fruitLabels[wheel2] != "CHERRY" && fruitLabels[wheel3] != "CHERRY")
        {
            credits = credits - bet;
            cout << "CHERRY - ANY - ANY" << endl;
            cout << "GOOD JOB! You won 5 credits." << endl;
            cout << "You currently have " << credits + 5 << " credits." << endl;
        }
        else ("YOU LOST!");
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slot Machine Problem
    By DecoratorFawn82 in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2013, 07:11 PM
  2. c programm slot machine change
    By schugh in forum C Programming
    Replies: 2
    Last Post: 05-17-2011, 05:23 PM
  3. Slot Machine program c++ bug
    By nobo707 in forum C++ Programming
    Replies: 12
    Last Post: 09-23-2009, 07:29 PM
  4. Slot Machine
    By nomi in forum C Programming
    Replies: 9
    Last Post: 01-03-2004, 10:13 AM
  5. IDEA: A Slot Machine (aka a fruit machine)
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:13 PM