Help with Roullete Program

Hello all,

I am working on developing this roulette program. I am trying to use dynamically allocated arrays as well as structs to make this program more manageable. I am needing some ideas on the arrays and in which ways I can use structs to help me.

I should be using a multidimensional array to hold the bet amount, type of bet, the net gain from the winnings/losings, etc. i am using switch statements for different types of bets that can be chosen. here maybe my code can explain more.

most stuff is there for ideas.

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstring>
#include <string>

using namespace std;


void singleNumberBet(int);
void redBlackBet();
void betOn12();
void firstSecondHalf();
void columnBet();

// developing struct, ideas for now.
struct SpinTheWheel
{
   int single, red, black, odd, even, first12, second12, third12, firstHalf,
      secondHalf, firstColumn, secondColumn, thirdColumn;
};



int main ()
{
   const int BET_LIMIT = 8; 
   int bet, betCount = 0, amount, betAmount, typeOfBet, singleNum, singleNumBet, numberOfBets;
   int *betArrayPntr;

   // Allow the user to enter the amount to enter the table with.
   cout << "Please enter the dollar amount to enter the table with.\n";
   cout << "Note, you may leave the table after any spin and are only alowed a max of 8 bets per spin.\n\n";

   cin >> amount;

   // input validation on amount.
   while (amount < 0)
   {
      cout<< "\n";
      cout << "You cannot enter the table with a negative amount, please re-enter your amount\n";
      cin >> amount;
   }
   cout << "\n";

   // ask user to enter bet type.
   cout << "Please enter the bet type\n"
      << "The choices are: 1.) Single Number\n"
      << "                 2.) Red/Black\n"
      << "                 3.) Odd/Even\n"
      << "                 4.) First, Second, Third 12\n"
      << "                 5.) First, Second Half\n"
      << "                 6.) First, Second, Third Column\n";
   cin >> typeOfBet;

   //input validation on bet type.
   while (typeOfBet < 1 || typeOfBet > 6)
   {
      cout << "\n";
      cout << "Please choose a correct option\n";
      cin >> typeOfBet;
   }

   // allow user to enter the number of bets
   cout << "Please enter the number of bets you would like to place\n";
   cin >> numberOfBets;

   // input validation on number of bets
   while (numberOfBets < 0 || numberOfBets > 8)
   {
      if (numberOfBets < 0)
      {
         cout << "You cannot place a negative number of bets, Please re-enter the number of bets\n";
         cin >> numberOfBets;
      }
      else if (numberOfBets > 8)
      {
         cout << "You cannot place more than 8 bets, please re-enter the number of bets\n";
         cin >> numberOfBets;
      }
   }

   // dynamically allocate a pointer array of ints.
   betArrayPntr = new int[BET_LIMIT];

   // switch statement for type of bet entered
   switch (typeOfBet)
   {

   case 1: 
      cout << "Please enter the numbers you would like to bet on, 0 - 36, and the amount for each bet.\n";

      for (betCount = 0; betCount < numberOfBets; betCount++)
      {
         cin >> singleNum;

         // input validation for numbers on the board
         while (singleNum < 0 || singleNum > 36)
         {
            cout << "Please enter a number within the possible numbers on the board\n";
            cin >> singleNum;
         }

         for (int i = 0; i < numberOfBets; i++)
         {
            cin >> singleBetAmount;

            // input validation for bet each bet amount.
            while (singleBetAmount < 0 || singleBetAmount > 10000)
            {
               cout << "Please enter a number within the possible range of the bet you may make.\n";
               cin >> singleBetAmount;
            }
         }
      }
      
      // there will be 5 more cases for the remaining choices.

   }


      // random number generated from 0 -36.

      // spin roulette wheel

      // ask the gambler if they would like to leave the table.

      // if yes, exit program

      // if no, continue program.



      system("pause");
      return 0;
   }

   // example functions for ideas for now.

   /*void singleNumberBet(int singleBet)
   {

   }

   void redBlackBet()
   {

   }

   void betOn12()
   {

   }

   void firstSecondHalf()
   {

   }

   void columnBet()
   {

   }*/
Last edited on
vaze159 wrote:
I am trying to use dynamically allocated arrays as well as structs to make this program more manageable.
Why do you think doing things the hard way will "make this program more manageable"? Have you heard of the standard containers C++ provides, such as std::vector? ;)
vaze159 wrote:
I should be using a multidimensional array
Why should you? If this is an assignment, you should be clear in what you are and are not allowed to do an what you are required to do, otherwise helping will be difficult.
Problem: You are to develop a program that simulates playing roulette.

The roulette wheel will be a modified version of an actual roulette wheel. It will only contain the numbers 0 - 36 (no 00). 0 is neither even, nor odd, nor red, nor black. The numbers 1-36 are associated with a color; either red or black (see http://www.predictem.com/images/roulette.gif).

The gambler will have the option of placing a maximum of 8 bets on the table per “spin”. The bets may be of any of the following types:

• Single number (0-36) – pays $35 for each $1 bet
• Red or black – pays $1 for each $1 bet
• Odd or even - pays $1 for each $1 bet
• First 12 (1-12), second 12 (13-24), or third 12 (25-36) - pays $2 for each $1 bet
• First half (1-18) or second half (19-36) - pays $1 for each $1 bet
• First column (1,4,7,10,13,16,19,22,25,28,31,34),
second column (2,5,8,11,14,17,20,23,26,29,32,35),
third column (3,6,9,12,15,18,21,24,27,30,33,36) – all columns pay $2 for each $1 bet

Please note that everything the gambler wins is in excess of the current bet. If a gambler bets $2 on a single number and wins he/she keeps the $2 bet and the casino gives him/her $70.

All information concerning the bets (type of bet, amount of bet, net gain, etc.) will be held in a dynamic array (possibly a multi-dimensional array). This array should be destroyed after each spin and a new one created for the next series of bets. The size of the array is determined by the number of bets placed per spin.

The gambler may never place a bet that would cause him/her to have negative dollars. The program should keep track of all bets placed for a spin and never let the gambler bet more than he/she has available. For example, if the gambler tries to place 4 bets and the third bet exceeds the amount of money available, that bet and all future bets that round are voided. The bet which exceeds the available amount should be set to 0 and the gambler should not be prompted for any more bets for that spin.

After collecting the bets from the gambler, spin the roulette wheel and determine the net gain of the gambler. Each spin should be a randomly generated number from 0 – 36. The gambler may leave the table after any spin. Once a bet is placed, the gambler must wait until the outcome of the spin to stop.


Input: To begin, the gambler should enter the amount of money available to play. Limit the maximum amount of money to begin at 10,000 dollars. The gambler must enter a number greater than zero. For each spin, your program should ask for the number of bets to be placed. For each bet placed, you should ask the type of bet and the amount of the bet. I recommend some type of menu system for the type of bet. Every bet must be a positive, whole number greater than zero, and the maximum bet is $500. If the gambler enters a floating point number for the bet, your program should handle it gracefully. How you handle it is up to you; just make sure the program doesn’t crash. After a spin, give the gambler the option to bet again or walk away.


Output: After each bet, display the amount of money left. All output pertaining to money should display the amount in whole dollars (no decimals needed) with a dollar sign. After a spin, indicate the net gain from the bets for that spin and the current amount of money the gambler has.

When the gambler leaves the table, thank the gambler for playing and display the total amount of winnings (or losses). For example, if the player started with $1000 and left the table with $1200, indicate the player won $200.


Miscellaneous: This program should use functions. There is no minimum or maximum. Remember that functions are there to do specific tasks. There should be minimal code in your main function other than function calls. As stated previously, your program must use dynamic arrays for the bets. The array must also be destroyed before another dynamic array is created.

just noticed that I did not do input validation on amount to enter and what not, will fix that
Last edited on
Topic archived. No new replies allowed.