Don't know what to do

This is a discussion on Don't know what to do within the C++ Programming forums, part of the General Programming Boards category; I really don't understand how to start this program off.Is it possible for someone to help me by giving me ...

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

    Exclamation Don't know what to do

    I really don't understand how to start this program off.Is it possible for someone to help me by giving me some pseudo code?. I don't know where to start or how to start. The program is below.


    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 JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44
    Can you be more specific?
    What do you mean by you don't know how to start it?
    "No! I must have my delicious cupcakes, my sweet cakey treasures, piping hot from their 40 watt WOMB!!!"
    --Captain Murphy

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Use top-down design to decompose your large problem into easy to manage modules which you can code as functions. You need to prompt, input, roll the wheel, output, etc. Each one of those tasks can be a function. By thinking of a problem like this, you take a large problem and break it up into smaller problems which you can solve and code. Before you code, decide what those modules will be, what specifically they will do, what parameters they will need, and what they will return. Then, coding should be a snap
    Good luck
    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.

  4. #4
    TampaBay
    Guest
    What is your bet?
    My bet is that this is homework and you haven't been paying attention.

  5. #5
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    im having trouble with this too, im not really sure how to arrange the functions or something...

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    #include <ctype.h>
    
    int funcgambling();
    int funcroll();
    
    int main()
    {
    
    while (gambling()=0)
    gambling();
    
    return 0;
    }
    
    int funcroll()
    }
    int temproll;
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    temproll=(rand() % 38+1);
    return (temproll)
    }
    
    
    int funcgambling()
    int cash=1000, bet, roll;
    roll=funcroll();
    cout << "What is your bet (1 - 1000, 0 to quit)?";
    cin >> bet;
    cout << "What do you want to bet on?\n\n1 - ODD\n2 - EVEN\n3 - First group (1-12)\n4 - Second group (13-24)\n5 - Third group (25-36)\n6 - specific number";
    cin >> choice;
    if (choice==1 && roll==1)
    cash = cash + 2*bet;

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

    Exclamation i'm stuck

    Okay. I posted a program about roulette not to long ago. I have written some of the code but I don't know where to go from there. I know that I need two useful functions but what would I use those functions for? Would I use one for the random generator? Am I doing the program right so far? Can I put if statments in the switch? For instance, if the user chooses ODD or Even, they would win the equivalent of there bet. Where would this info go?

    Here's what I have so 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;

    }

  7. #7
    lurker
    Guest
    You can create functions for almost anything, just think of groups of code that you can put together by themselves. For instance, I took your code, and created a function called startgame.
    Code:
    //startgame function prototype
    void startgame(int &betamt, int &playerstot, int &betchoice);
    
    
    //startgame function definition
    void startgame(int &betamt, int &playerstot, int &betchoice)
    {
    bool validbetamt = true;
    
    cout << "Let's play some roulette!" << endl
         << "You will start with $1000." << endl;
    
       //This do-while statement asks for the amount of the bet and 
       //verifies that it is a valid amount
    
    do(
    cout<< "What is your bet ( 1 - 1000, 0 to quit)?" << endl;
    cin >> betamt;
    
    if(betamt > playerstot)
       {
       cout<<"The amount you bet is greater than the amount you "
           <<"have, please try again. " <<endl;
       validbetamt = false;
       }
    }while (!validbetamt)
    
    if (betamt != 0)
       {
       cout << "What do you want to bet on?" << endl
            << " 1 - ODD" << endl
            << " 2 - EVEN" << endl
            << " 3 - First group (1 - 12)"<< endl
            << " 4 - Second group (13 - 24)" << endl
            << " 5 - Third group (25 - 36)" << endl
            << " 6 - specific number" << endl
            << "Enter choice (1-6): " << endl;
       cin >> betchoice;
       }
    }
    so now your main program will look like this:
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    
    using std::cout;
    using std::endl;
    using std::cin;
    
    int main ()
    
    {
    int bet, choice = 0;
    int playerstotal
    
    startgame(bet, playerstotal, 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;
       }
    Once you get this working correctly, you can move on to the next piece. By creating functions, you can work on the program piece by piece, and fixing syntax and/or logic errors can be done as you code, and can be easier to narrow down. (My code has not been compiled, so there may be errors) (By the way, you should use code tags for your code, it makes it much easier to read). One suggestion, perhaps the 'choice' should be a 'char' instead of an int.

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

    Exclamation 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

Popular pages Recent additions subscribe to a feed

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