Help with roulette program

This is a discussion on Help with roulette program within the C++ Programming forums, part of the General Programming Boards category; I am trying to create 2 roulette wheels(american & european) The american wheel has numbers ranging from 1-36,0,& 00........the european ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    Help with roulette program

    I am trying to create 2 roulette wheels(american & european) The american wheel has numbers ranging from 1-36,0,& 00........the european wheel has numbers from 1-36 & 0 (the wheels are suppose to spin and give you a random number in those number ranges). The program is just suppose to run and NOT interact with the user. The bet is 6 random numbers which are $1.00 each. I need to show the amount of money(won or lost) at spin 25..250..2,500..25,000..& 250,000. It's a console apt. Im stuck because when i run this program it shows the same thing twice and in the american column it shows 130130 and nothing in the european column. Please help thanks in advance.



    Code:
    #include <iostream>
    #include <cstdlib>
    #include <iomanip>
    #include <stdlib.h>
    #include <cmath>
    
    using namespace std;
    
    void showArray (int [6][1][1], int);
    
    int getBet()
    {
       int seed = 6;
       int bet = 1 + (rand () % 38);
       srand (seed);
       return bet;
    }
    
    int getSpinA()
    {
       int seed = 1;
       int spin = 1 + (rand () % 38);
       srand (seed);
       return spin;
    }
    
    int getSpinE()
    {
       int seed = 1;
       int spin = 1 + (rand () % 37);
       srand (seed);
       return spin;
    }
    
    double money (100.00);                    //starting money
    int main()
    {
       double  a, e, euro, total;
       cout << (left) << setw (18) << "N" << setw (10) << "$" << (right) << setw (5) << "e" << endl;
       cout << "________________________________________" << endl;
    
    
       for (int count = 0; count <= 250000; count++)
       {
    
           for (int play = 0; play <= 6; play++)
           {
               getBet();
               getSpinA();
               getSpinE();
               total = money - 6.00;                //each bet is a dollar
               euro = money - 6.00;
    
    
               if ((count == 25)&& getBet() == getSpinA()|| getSpinE())                //win
               {
                   a = total + 36.00;
                   e = euro + 36.00;
                   cout << (left) << setw (15) << "25" << a << e << endl;
                   if ((count == 25) && getBet() != getSpinA()|| getSpinE())            //lose
                   {
                       cout << (left) << setw (15) << "25" << a << e << endl;
    
                       if ((count == 250) && getBet() == getSpinA()|| getSpinE())                //win
                       {
                           a = total + 36.00;
                           e = euro + 36.00;
                           cout << (left) << setw (15) << "250" << a << e << endl;
                           if ((count == 250) && getBet() != getSpinA()|| getSpinE())            //lose
                           {
                               cout << (left) << setw (15) << "250" << a << e << endl;
    
                               if ((count == 2500) && getBet() == getSpinA()|| getSpinE())                //win
                               {
                                   a = total + 36.00;
                                   e = total + 36.00;
                                   cout << (left) << setw (15) << "2500" << a << e << endl;
                                   if ((count == 2500) && getBet() != getSpinA()|| getSpinE())            //lose
                                   {
                                       cout << (left) << setw (15) << "2500" << a << e << endl;
    
                                       if ((count == 25000) && getBet() == getSpinA()|| getSpinE())            //win
                                       {
                                           a = total + 36.00;
                                           e = total + 36.00;
                                           cout << (left) << setw (15) << "25000" << a << e << endl;
                                           if ((count == 25000) && getBet() != getSpinA()|| getSpinE())        //lose
                                           {
                                               cout << (left) << setw (15) << "25000" << a << e << endl;
    
                                               if ((count == 250000) && getBet() == getSpinA()|| getSpinE())            //win
                                               {
                                                   a = total + 36.00;
                                                   e = total + 36.00;
                                                   cout << (left) << setw (15) << "250000" << a << e << endl;
                                                   if ((count == 250000) && getBet() != getSpinA()|| getSpinE())        //lose
                                                   {
                                                       cout << (left) << setw (15) << "250000" << a << e << endl;
                                                   }
                                               }return 0;
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Help with roulette program

    >>it shows the same thing twice
    That's to do with your logic. I strongly recommend you review all those imbedded "if" statements.

    >>and in the american column it shows 130130 and nothing in the european column.
    Well, look at your code, when you output a and e, is there any white space between them? If there isn't, what do you think the output will look like? (hint: setw() is only remember for the next output)
    Code:
    cout << (left) << setw (15) << "25" << a <<e << endl;
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Code:
    (a != b || c)
    // is not the same as
    (a != b || a != c)
    Don't use global variables. Use more descriptive identifiers. Seed your random number generator only once at the beginning of main() using the current time.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21