confused about random generator

This is a discussion on confused about random generator within the C++ Programming forums, part of the General Programming Boards category; This program is about roulette. Has anyone ever had to write a roullette game? If so, how did you use ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    confused about random generator

    This program is about roulette. Has anyone ever had to write a roullette game? If so, how did you use the rand function? The number are between 0, 00 to 38. would I use a for statement? How do you tell when the ball rolls? Do I put that info in the main function, make up a function or put it in the rand fuction? Can i have an example. It helps me better to have a visual. Here's what I've written thus far:

    #include <iostream>
    #include <cstdlib>
    #include <ctime>

    using std::cout;
    using std::endl;
    using std::cin;
    int main ()

    {
    int bet, choice = 0;
    cout << "Let's play some roulette!" << endl;

    cout << "You will start with $1000." << endl;

    cout << "What is your bet ( 1 - 1000, 0 to quit)?" << endl;
    cin >> bet;
    cout << "What do you want to bet on?" << endl;

    cout << " 1 - ODD" << endl;
    cout << " 2 - EVEN" << endl;
    cout << " 3 - First group (1 - 12)"<< endl;
    cout << " 4 - Second group (13 - 24)" << endl;
    cout << " 5 - Third group (25 - 36)" << endl;
    cout << " 6 - specific number" << endl;

    cout << "Enter choice (1-6): " << endl;
    cin >> choice;
    switch (choice) {

    case 1:
    cout << "You chose odd" << endl;
    break;

    case 2:
    cout << "You chose even" << endl;


    break;

    case 3:
    cout << "You chose first group (1 - 12)"<< endl;
    break;

    case 4:
    cout << "You chose second group (13 - 24)"<< endl;
    break;

    case 5:
    cout << "You chose third group"<< endl;
    break;

    case 6:
    cout << "You chose specific number" << endl;
    break;

    default:
    cout << "Program should never get here!!" << endl;
    }




    while ( bet != 0 ) {

    cout << "What is your bet ( 1 - 1000, 0 to quit)?" << endl;
    cin >> bet;
    }



    return 0;

    }



    Task:You are to write a program that will allow a user to play a simplified version of roulette. The sample execution given below should help demonstrate the expected behavior and the error checking required. If you lose on a turn, then you lose your bet. If you win on a turn, then for ODD/EVEN you win the equivalent amount of your bet. For a 1/3 RANGE bet (first group, second group, third group), you win 2 times your bet. When betting on a specific number, you win 35 times your bet. Also notice that the roulette wheel contains 38 equally probable numbers: 0, 00, 1, 2, ... 36. When 0 or 00 comes up, you lose ... regardless of the bet.
    Rules and Requirements:
    1) Start the user out with $1000. The game should loop until the user enters a 0 bet (the signal to cash out) or until the user goes bankrupt (no money left). Upon cashing out, you should print out the user's final monetary total. When a game ends, ask the user if he/she wants to play again (y/n). If the user answers yes, start another game, beginning agiain at $1000. If no, quit the program. If an invalid character is entered, print an error message and make the user re-enter their response. (You may assume the input to this question will be a single character).
    2) For each spin of the wheel, first ask the user for the amount of the bet, then for what type of bet. Negative bets are illegal, as are bets larger than the amount of money you have, and there are only six valid menu choices (as shown in the sample execution). Upon an illegal entry, print an error message and prompt the user to re-enter. If the user wants to bet on a specific number, have the user input this as well (and error check the value). Valid numbers on the wheel are 1 through 36.

    Note: For all of these inputs, you may assume the correct type of input. (All of the inputs described in item (2) above are integers). You only need to error check on values.

    3) You will need to use random number generation to simulate the spinning of the roulette wheel. Make sure to include the appropriate libraries.

    4) Your output doesn't have to match the sample execution word for word, but it must contain all of the elements that are shown in the sample run. For example, when prompting for the bet, you must print the possible range allowable for the bet (this varies based on the amount of money you have).

    5) General Requirements
    No global variables, other than constants!
    You must use two or more useful functions in your program. (For example, if you write the entire program in a function, then write main() so that it does nothing but call that function, this does not count as useful). Between your two or more functions, you must use at least one useful parameter, and one useful return.
    You may use the libraries: iostream , cstdlib, ctime. (The last two are for the random number generation).

    Sample output:

    Let's play some roulette!

    You will start out with $1000.

    What is your bet (1 - 1000, 0 to quit)? 500
    What do you want to bet on?

    1 - ODD
    2 - EVEN
    3 - First group (1-12)
    4 - Second group (13-24)
    5 - Third group (25-36)
    6 - specific number

    Enter choice (1-6): 2
    The ball lands on 2.
    You win $500.
    You now have $1500

    What is your bet (1 - 1500, 0 to quit)? 1

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Code:
    srand((unsigned)time(0));
    int roll = rand() % 38;
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. How exactly does the random number generator work?
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2007, 12:46 AM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 09:56 AM
  4. Testing Random Number Generator
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 08-12-2005, 12:48 AM
  5. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 07:10 AM

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