roulette

Roulette in c++ is a popular casino game that we will be implementing in this practice assignment. If you don’t know what Roulette is, it’s a casino game, where the player chooses to place bets on either a single number or a range of numbers, the colors red or black, or whether the number is odd or even.

This implemented version of roulette in c++ is only basic, the program flow follows as this

  1. The Game starts
  2. The user places how much he/she wants to bet
  3. The user chooses either to bet on a specific number, black or red, or an odd/even number
  4. The game will generate the random number
  5. The game will decide whether the player wins or loses
//----------------------------------------------------
// Roulette in C++
//----------------------------------------------------
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{

    // Set as CONSTANT for Random number generation
    int const MIN_NUMBER = 1, MAX_NUMBER = 36;
    int number;
    int random;
    int my_money;
    int starting_money;

    double bet, winnings = 0;

    // Use arrays for player decision
    char gametype;
    char evenodd;
    char blackred;
    char stop = 'N';

    // Main Menu Screen
    cout << "Welcome to ROULETTE\n\n";
    cout << "With how much money do you want to start?\n";
    cin >> starting_money;
    my_money = starting_money;

    while (my_money > 0 && stop != 'Y')
    {
        my_money = my_money + winnings;
        winnings = 0;
        cout << "How much would you like to bet?\n";
        cin >> bet;

        while (bet > my_money)
        {
            cout << "How much would you like to bet?\n";
            cin >> bet;
        }


        cout << "Would you like to bet on a specific number (N), on odd/even (O) or on Black/Red(B)? ";
        cin >> gametype;

        // User selects a specific number to place bet on
        if (gametype == 'n' || gametype == 'N')
        {
            cout << "What number would you like to bet on? "; cin >> number;
            if (number == 00)
                number = 37;

            srand(time(NULL));
            random = rand() % (MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER;

            //cout << "The ball landed on " << random << "\n";

            // Lose
            if (number != random)
            {
                cout << "The ball landed on " << random << "\n";
                cout << "You lose $" << bet << "\n";
                winnings -= bet;
            }
            // Win
            else
            {
                cout << "The ball landed on " << random << "\n";
                cout << "You win $" << 35 * bet << endl;
                winnings += 35 * bet;
            }
        }

        // User selects even or odd
        if (gametype == 'o' || gametype == 'O')
        {
            cout << "Would you like to bet on even (E) or odd (O)? "; cin >> evenodd;

            srand(time(NULL));
            random = rand() % (MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER;
            cout << "The ball landed on " << random << endl;

            // selects EVEN
            if (evenodd == 'E')
            {
                // even win
                if (2 * (random / 2) == random)
                {
                    cout << "You win $" << bet << endl;
                    winnings += bet;
                }
                // even lose
                else
                {
                    cout << "You lose $" << bet << endl;
                    winnings -= bet;
                }
            }

            // selects ODD
            if (evenodd == 'O')
            {
                // odd lose
                if (2 * (random / 2) == random)
                {
                    cout << "You lose $" << bet << endl;
                    winnings -= bet;
                }
                // odd win
                else
                {
                    cout << "You win $" << bet << endl;
                    winnings += bet;
                }
            }
        }

        if (gametype == 'B' || gametype == 'b')
        {
            cout << "would you like to bet on black (B) or red (R)? "; cin >> blackred;

            srand(time(NULL));
            random = rand() % (MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER;
            cout << "The ball landed on " << random << endl;

            if (blackred == 'B' || blackred == 'b')
            {
                if (random == 2 || random == 4 || random == 6 || random == 8 || random == 10 || random == 11 || random == 13 || random == 15 || random == 17 || random == 20 || random == 22 || random == 24 || random == 26 || random == 28 || random == 29 || random == 31 || random == 33 || random == 35)
                {
                    cout << "You win $" << bet << endl;
                    winnings += bet;
                }
                else
                {
                    cout << "You lose $" << bet << endl;
                    winnings -= bet;
                }
            }

            if (blackred == 'R' || blackred == 'r')
            {
                if (random == 2 || random == 4 || random == 6 || random == 8 || random == 10 || random == 11 || random == 13 || random == 15 || random == 17 || random == 20 || random == 22 || random == 24 || random == 26 || random == 28 || random == 29 || random == 31 || random == 33 || random == 35)
                {
                    cout << "You lose $" << bet << endl;
                    winnings -= bet;
                }
                else
                {
                    cout << "You win $" << bet << endl;
                    winnings += bet;
                }
            }
        }
        cout << "Do you want to stop, yes(Y) or no(N)?";
        cin >> stop;
    }

    // Final Results
    my_money = my_money + winnings;
    cout << "You won a total of $" << my_money - starting_money << "\nAnd you currently have a total of $" << my_money;
}

 

Share this post

FAQ's

How to make a roulette game in c++?

To make a basic roulette game in C++, you will need to implement a random number function to see if the ball lands on a number between 1-36 and if it lands on either black or red