GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Nov-2006, 17:34
mfm1983 mfm1983 is offline
New Member
 
Join Date: Nov 2006
Posts: 5
mfm1983 is on a distinguished road
Post

Text-Based Roulette Game


Sorry for how long this is, but this describes in detail what I want to accomplish, followed my my code. Thanks in advance for reading all of this. I've been working on this code for days!

First of all, I would like to thank anyone that takes the time to read and respond to my thread. I am still currently in my first semester of programming and taking a small c++ class in college. To get a better understanding of what a single line of code could possibly represent I'm starting my first project with an interest I have. The program I want to create is not necessarily a game, but could be converted as such. What I aim to accomplish is to make a game related program that tests probabilty and other statistics.

The biggest difficulty for me is I have written simple programs that consist of asking for a series of numbers and it would calculate the sum, difference, average, etc. The algorithms required for the program I want is a little more advanced then anything we have done in class thus far. To me the difficulty makes the project more fun, and I don't think that it is out of my abilities completely. I would like some guidance from anyone interested in giving me advice and/or algorithm help on designing a basic program.

This next portion says in so many words what I want to get out of my program. In advance I am sorry for how long this is, but I wanted to try and be clear on what I want my program to do. If there are holes in the way I am thinking of setting this up let me know.


I want it to just show text saying "Welcome! How much would you like to deposit into our casino? Only use numerical values! <= 1" Else, the message repeats until you give an accepted answer. Then, output $ "X Dollars". For example, for 1000 would output "You have deposited $1000 good luck!"

Next, it asks "What wheel would you like to place your bets on?" "American" and "European" are the only accepted answers. Else, repeat statement until accepted answer is typed. Exception for the wrong answers in the future is "Floor". This will bring the player back to this question at any time. "What wheel would you like to place your bets on?"

Next, it asks "Would you like to bet using a loop? Yes or No?" Typing Y, N, Yes, and No, would be the only accepted answers. Else, it would repeat the statement until you gave the right choice.

Next, if "Yes" is choosen it asks "How many spins would you like the roulette wheel to make?" Only whole numbers are to be accepted in this portion of the program. Else, repeat question. If "No" is choosen less questions should be asked. "How much would you like to bet?", "Where would you like to place your bets?", and "Would you like the croupier to spin?" options should follow.

Next, it asks "How much money would you like to bet for the requested amount of spins?" Only whole numbers should be accepted here as well to make it easier for calculations and testing <= 1. The feedback to the answer should be "Would you like your $ "X Dollars" disbursed?" For example, 1000 should respond with "Would you like your $ 1000 disbursed?"

"No" implies that only one bet is going to be placed and "Yes" implies that $"X Dollars" will be divided among the number of bets you place. Same same thing should apply for eaither a looped bet or single bet. The reason is to show the results of a consistent bet. The acceptable yes or no answers apply here too.

Next, I would like the croupier (program) to ask "How many bets would you like to place?" Whole numbers should only be accepted here as well <= 1.

Next, "What is your starting bet?" Whole numbers only allowed.

Next, "What is your maximum bet?" Whole numbers only allowed.

Next, "Would you like to increase your bets as you win or lose?"

"Yes" asks would you like your bets to increase as you win or lose?" "Win" and "Lose" are the only options.

Next, "How would you like to increase your betting? Only whole numbers and 'N' or 'n' is allowed to increase the betting by the number of spins." I would like this part of the program to even process equations involving powers. For example, I would like to be able to put "(1^n + 10)". If the starting bet is $10 and you lost three times in a row the third bet would be (1^3 + 10) = (3 + 10) = 13. I know this is a dumb bet since you would not even break even. This is simply an example. My teacher never went into powers, but he did go into using '%'.

Next, it should ask Would you like to enable temporary betting? "Yes" and "No" applies with "Details" as an added option.

If "Details" is selected it should say "The temporary betting feature prevents a gambler from betting too high and losing all of his money on a high streak! When your current bet exceeds the maximum bet, temporary betting automatically works for that spin."

"Yes" asks "What would you like to set your temporary bet as?" Whole numbers only allowed.

Temporary betting is only enabled when the next spin would exceed the maximum bet. Also, it is disabled once a spin results in a win, or the loop is terminated. When a win occurs, the starting bet is applied before the next spin.


Display Table Now!


Before you place your bets it will now show a table of what bets you can place, the payout, and what numbers would win. For example, a "Five-Number Bet" and "Odd Bet" would display "The payoff on your Five-Number Bet is 6 to 1!" and "0, 00, 1, 2 or 3 wins!" and "The payoffon your Odd bet is 1 to 1!" and "All odd numbers win!" The Five-Number Bet is only an option on the "American Wheel" option and I have to have certain bets and values to spin on not available depending on what wheel is used.

Next, based on the number of bets you place it will ask "Where would you like to place your bets?" If you follow the betting options you proceed to the next question.

Next, it needs to calculate the amount of money you wished to bet per spin divided by the number of bets placed.

Next, it needs to summarize the options choosen for the bets.

Next, it needs to ask if the bets placed are correct. Yes and no options are the same once again.

Next, it asks "Would you like the croupier to spin at this time?" Yes and no options are the same once again.

At this time results should be being generated. Program should stop at the end of the loop, after one spin if no loop is selected, or if there isn't enough money to cover the current bet for the loop. Once the betting stops it shows how much you earned.

Next, the program says "Are you ready to continue with the results?" Only "Yes" works unless once again if you type "Floor" to take you back to the casino floor. Else, repeat previous statement until a correct answer is typed.

Next, With a "Yes" list how many times in a row (streak) both your bet had won and lost in a row with five and more as the value of the streak. Also, if a streak of ten occurs it should not indicate that a streak of five occured twice and ten occured once. Then, it should indicate how many times the bet had to be reset to the starting bet due to a high streak, if requested to increase bets based on wins or losses until you can not cover the bet with the range selected. Also, if enabled how many spins was temporary betting used.


If this occurs the first thing that should happen is if a temporary bet is
selected, that amount should be used for future spins until the win or loss
option selected results in terminating the temporary bet. This is only used so
long streaks do not cause you to lose all of your money. If you can't cover
any bet it should automatically bet the original amount and continue to increase as it did before. However, if the current funds can not even cover the temporary
bet or starting bet, then the loop is terminated. As stated above!


After the report the program should ask. "Would you like to place anymore bets?" Yes and no answers apply.

"No" brings back to casino floor with new bankroll.
"Yes" asks "Would you like to repeat your bets? with or without the money you earned?" Only "With" and "Without" applies.

"With" uses new bankroll to place same bet.
"Without" gives away earnings and tests the betting again.

I think this was really detailed...maybe too detailed, but I hope it was a good outline of what I want to accomplish. Also, I hope what I typed can help anyone give me some guidance on writing my program. I figure I'm doing great if I can eventually make this program and understand it. Even if I get help from you fellow programmers along the way. Thanks in advance to those that assist me or read my post at least.

CPP / C++ / C Code:
/* Text-Based Roulette Game - Michael - e-mail

   C program to prompt user to answer a series of questions and print the
   results based on the user's input.
*/

#include <iostream.h> // include system information

int main() {
  int new, exit, q_begin, q_deposit, q_wheel, q_loop, q_numberspins, q_bet,  
  q_disbursedbet, q_numberbets, q_startingbet, q_maximumbet, q_increasebet, 
  q_increasebetwinlose, q_increasebetopposite, q_temporarybets q_temporarybetsvalue, 
  q_eachbetvalue, q_placebets, q_confirmbet, q_modifybet, q_newbets, q_spinwheel, 
  q_repeatbet, q_currentbankroll;

char Streak = 'n';   // Win or Loss streak counter
char Win    = 'w';   // Win counter
char Lose   = 'l';   // Lose Counter


// This defines each variable and its role in the program. 
// Basically what I want the variables to do, 
// but I'm not skilled enough to get them to.
/*

new - New game

exit - Exit game

q_begin - After user inputs data begin prompting the user for game input

q_deposit - $"X Dollars" to deposit into the casino

q_wheel - Type of wheel to display later
(Choose between the American and European Wheel)

q_loop - Enable or Disable multiple spins 
(Useful for testing out numerous spins with fixed betting)

q_numberspins - Number of spins

q_bet - $"X Dollars" to bet

q_disbursedbet - Enable or Disable multiple bets

q_numberbets - Number of bets

q_startingbet - Sets the "starting bet" amount and 
the amount of the reset bet when the streak resets.

q_maximumbet - Sets the maximum bet
If the next bet and spin will exceed the "maximum bet" and 
"temporary betting" is enabled, use that set amount until the streak is reset.
Else, restart at the "starting bet" amount for the next spin.

q_increasebet - Enable or Disable increasing bets 

q_increasebetwinlose - Increase bets as you win or lose

q_increasebetopposite - Opposite of "q_increasebetwinlose" selection
Determines when 'n' will reset.

q_increasebetequation - Equation user inputs 
To determine how the bet will increase based on 
the win or loss streak. 

char Streak = 'n' - Win or Loss streak counter
Bet will automatically increase based on this variable in the equation.

q_temporarybets - Enable or Disable temporary bets
"Temporary betting" is only used if enabled and the following spin 
will result in betting an amount that exceeds the "maximum bet"
If active the bet will return to the "minimum bet" amount 
after the streak is reset. 
Else, skip step and return to the "starting bet" amount.
(Useful for long streaks!)

q_temporarybetsvalue - $"X Dollars" set for temporary bet

q_eachbetvalue - $"X Dollars" calculated using ( q_bet / q_numberbets )

q_placebets - Where bets are placed

q_confirmbet - Confirm bet options

q_modifybet - If bet not correct use integers to modify bet options

q_currentbets - When bets have been changed this value stores them

q_spinwheel - Spin wheel

q_repeatbet - Enable or Disable repeat bet option

q_updatebankroll - Update bankroll option

q_currentbankroll - Bet with current bankroll

q_oldbankroll - Bet again with old bankroll
(Usful for repeating tests, and if you like to donate to charity!)

char Win - To keep track of all of the win streaks 
that occured during the multiple spins <= 5

char Lose - To keep track of all of the lose streaks 
that occured during the multiple spins <= 5

*/
// End defining variables

  // Display initial program identification
  cout << "Text-Based Roulette Game" << endl
       << "" << endl << endl;


  // Print menu options and prompt to continue
  cout << "new - New game 
  << endl
  "exit - Exit game
  << endl << endl;
  cout << "Press Y or Yes to continue";
  cin >> q_begin;
  cout << endl;
  // After user inputs "Y" or "Yes" go to the
  // "Make a deposit" option 


  // Begin prompting the user for game input


  // Make a deposit
  cout << "Welcome! How much would you like to deposit into our casino? $
  << endl
  Note: Only use whole numbers <= 1!"
  << endl;
  cin >> q_deposit;
  cout << endl;
  // After user inputs a whole number <= 1, save the value 
  // and go to the "pick a wheel" option 
  

  // Pick a wheel
  cout << "What wheel would you like to place your bets on? 
  << endl
  Note: Only type A, E, American, European!"
  << endl;
  cin >> q_wheel;
  cout << endl;
  // After user inputs "A", "E", "American", or "European", save the value
  // and go to the "Loop" option

      // "A", and "American" - will later display the American Roulette table
      // "E", and "European" - will later display the European Roulette table
  

  // Enable or disable multiple spins
  cout << ""Would you like to bet using multiple spins? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_loop;
  cout << endl;
  // Depending on user input go to "Enable", or "Disable" 
  // "Loop" option 
 

    // Enable loop and ask for number of spins
    cout << "How many spins would you like the roulette wheel to make? 
    << endl
    Note: Only use whole numbers <= 1!"
    << endl;
    cin >> q_numberspins;
    cout << endl;
    // After user inputs a whole number <= 1, save the value
    // and go to the "Disburse bet" option 


    // Disable loop and go to the "Place bet" option

  // Place a bet
  cout <<"You have $"<< q_deposit 
  << endl
  cout << "How much money would you like to bet? $
  << endl
  Note: Only use whole numbers <= 1!"
  << endl;
  cin >> q_bet;
  cout << endl;
  // After user inputs a whole number <= 1, save the value
  // and display a "Roulette table"


  // Enable or disable disburse bet
  cout << "Would you like your $" << q_bet << 
  cout << "disbursed
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_disbursedbet;
  cout << endl;
  // Depending on user input goto "Enable", or "Disable" 
  // "Disburse bet" option 
  
 
    // Enable disbursed bet and ask for number of bets
    cout << "How many bets would you like to place?
    << endl
    Note: Only use whole numbers < 1!"
    << endl;
    cin >> q_numberbets;
    cout << endl;
    // After user inputs a whole number <= 1, save the value
    // and go to the "Starting bet" option


    // Disable disbursed bet goes to 
    // "Starting bet" option with only 
    

  // Place a starting bet 
  cout << "What is your starting bet? $ 
  << endl
  Note: Only use whole numbers <= 1!"
  << endl;
  cin >> q_startingbet;
  cout << endl;
  // After user inputs a whole number <= 1, save the value
  // and go to the "Maximum bet" option
  

  // Place a maximum bet
  cout << "What is your maximum bet? $
  << endl
  Note: Only use whole numbers <= 1!"
  << endl;
  cin >> q_maximumbet;
  cout << endl;
  // After user inputs a whole number <= 1, save the value
  // go to the "Increase bet" option


  // Increase bet as you win or lose
  cout << "Would you like to increase your bet as you win or lose? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_increasebet;
  cout << endl;
  // Depending on user input goto "Enable", or "Disable" 
  // "Increase bet" option 


    // Enable increase bet ask to increase for win or lose
    cout << "Would you like the bet to increase as you win or lose? 
    << endl
    Note: Only type W, L, Win, Lose!"
    << endl;
    cin >> q_increasebetwinlose;
    cin >> q_increasebetopposite; // Opposite of input generates this value
    cout << endl;
    // Depending on user input save "Win", or "Lose" data,
    // Else the option you did not choose will reset 
    // the next bet amount to the starting bet amount
    // and go to the "Increase bet equation" option 
  
    // Disable increase bet go to 
    // "Temporary bet" option
    

  // Increase bet equation
  cout << "Enter an equation to increase bets
  << endl
  Note: Only use integers, and 'n' to generate an equation
  << endl
  'n' = current number of spins that occurs
  before the q_increasebetopposite value occurs
  << endl  
  example: (1^n) + 5  ... If n=4,  The bet would now be (1^4) + 5 = (4 + 5) = 9
  << endl                         
  The n term would be four, if you won or lost three spins in a row!
  This is because you are on your 4th spin in the streak.
  << endl
  cin >> q_increasebetequation;
  cout << endl;
  // Depending on user input save "Equation" data,
  // and go to the "Temporary bet" option


  // Enable or disable temporary bets
  cout << "Would you like to enable or disable temporary bets? 
  << endl
  Note: Only type Y, N, D, Yes, No, Details!"
  << endl;
  cin >> q_temporarybets;
  cout << endl;
  // Depending on user input goto "Enable", or "Disable" 
  // "Temporary bet" option 


      // Enable temporary bets
      cout << "What would you like to set your temporary bet as? $
      << endl
      Note: Only use whole numbers <= 1!"
      << endl;
      cin >> q_temporarybetsvalue;
      cout << endl;
      // After user inputs a whole number <= 1, save the value
      // and go to the "Display Roulette Table" option

      // Disable temporary bets 
      // go to "Display Roulette Table" option

      // Details temporary bets
      cout << "The temporary betting feature prevents a gambler from betting 
      too high and losing all of his money on a high streak! When your current 
      bet exceeds the maximum bet, temporary betting automatically works for 
      that spin."      
      << endl;
      // Following this statement return to "Enable" or "Disable" 
      // "Temporary bet" option




  // Display Roulette Table depending on user's table choice
  // After table prints go to the
  // "Place bet" option

  
  // American Roulette Table
  cout<<"0 |1  4  7  10 13 16 19 22 25 28 31 34|1stColumn"<<endl 
      <<"--|2  5  8  11 14 17 20 23 26 29 32 35|2ndColumn"<<endl 
      <<"00|3  6  9  12 15 18 21 24 27 30 33 36|3rdColumn"<<endl 
      <<"--|    1st12  |    2nd12  |   3rd12   |---       "<<endl 
      <<"  | 1stHalf  |  Even |  ODD | 2ndHalf |          "<<endl<<endl; 

  // American Roulette Profit Margin 
 cout<<"           The Profit Margin"<<endl 
     <<"            +-------------+"<<endl 
     <<"            |EVEN    | 2X |"<<endl 
     <<"            |ODD     | 2X |"<<endl 
     <<"            |Halves  | 2X |"<<endl 
     <<"            |Columns | 3X |"<<endl 
     <<"            |12ths   | 3X |"<<endl 
     <<"            |Numbers | 35X|"<<endl 
     <<"            +-------------+"<<endl<<endl; 


  // European Roulette Table
  cout<<"0 |1  4  7  10 13 16 19 22 25 28 31 34|1stColumn"<<endl 
      <<"--|2  5  8  11 14 17 20 23 26 29 32 35|2ndColumn"<<endl 
      <<"00|3  6  9  12 15 18 21 24 27 30 33 36|3rdColumn"<<endl 
      <<"--|    1st12  |    2nd12  |   3rd12   |---       "<<endl 
      <<"  | 1stHalf  |  Even |  ODD | 2ndHalf |          "<<endl<<endl; 

  // European Roulette Profit Margin 
 cout<<"           The Profit Margin"<<endl 
     <<"            +-------------+"<<endl 
     <<"            |EVEN    | 2X |"<<endl 
     <<"            |ODD     | 2X |"<<endl 
     <<"            |Halves  | 2X |"<<endl 
     <<"            |Columns | 3X |"<<endl 
     <<"            |12ths   | 3X |"<<endl 
     <<"            |Numbers | 35X|"<<endl 
     <<"            +-------------+"<<endl<<endl;  




  // Place your bets
  cout << "Where would you like to place your bets? 
  << endl
  Note: Type a series of words you see on the table. Use the spacebar to 
  seperate bets!"
  << endl;
  cin >> q_placebets;
  cout << endl;
  // Depending on user input save data to print later
  // go to the "Calculate bet" data 
 
  
  // Calculate the amount of money you wished to bet per spin 
  // divided by the number of bets placed.
  cout << "You have placed $" << q_eachbetvalue <<
  cout << "on" << q_placebets <<
  cout << endl;
  // go to "Print summary"
  

  // Print Summary of all selections made throughout the program
  cout << endl
  "1) Y << endl
  2) Selection #2 << endl
  3) Selection #3 << endl
           etc...";
  // go to the "Confirm bet" option


  // Confirm bet
  cout << "Has your bet been placed correctly? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_confirmbet;
  cout << endl;
  // Depending on user input goto "Correct", or "Not correct" option 
  

    // If bet is correct go to the "Spin wheel" option
    

    // Bet is not correct  
    cout << "What options are not correct? 
    << endl
    Note: Only use whole numbers <= 1 
    Use the spacebar to seperate options!"
    << endl;
    cin >> q_modifybet;
    cout << endl;
    // go to the "Input new values" option
    
    

      // Allow user to input new values for each option selected 
      cout << "Input new values for options selected! 
      << endl
      Note: Use the spacebar to seperate the values modified"
      << endl;
      cin >> q_currentbets;
      cout << endl;
      // Print new summary and go to the "Confirm bet" option
       

  // Spin wheel
  cout << "Would you like the croupier to spin the wheel? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_spinwheel;
  cout << endl; 
  // Depending on user input goto the "Spin", or "Don't spin" option
       

    // Spin wheel and collect data and print to user
    cout << "Printed Data" 
    << endl
     
    // Don't spin wheel and display message
    cout << "What are you waiting for is something else wrong? 
    << endl
    Note: Confirm your bet again!"
    // Return to the "Confirm bet" option


  // After data is printed choose to repeat the bets
  cout << "Would you like to repeat the bets? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_repeatbet;
  cout << endl;
  // Depending on user input goto the
  // "Yes", or "No" option
 

    // If yes is choosen go to the
    // "Current bankroll" option
    

    // If no is choosen save current bankroll, 
    // and return to the "Pick a wheel" option with current bankroll
 

  // Update bankroll
  cout << "Would you like to repeat your previous bets with or without your 
  current bankroll? 
  << endl
  Note: Only type Y, N, Yes, No!"
  << endl;
  cin >> q_updatebankroll;
  cout << endl; 
  // Depending on user input goto the 
  // "Yes", or "No" option
      
    
    // If yes spin wheel again with the current bankroll
    cin >> q_currentbankroll;  
      
    // If no spin wheel again without the current bankroll 
    // (Good for repeating tests)
    cin >> q_oldbankroll;

  


  return 0;
}
Last edited by LuciWiz : 29-Nov-2006 at 04:11. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 27-Nov-2006, 19:16
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,148
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Text-Based Roulette Game


Quote:
Originally Posted by mfm1983
Sorry for how long this is, but this describes in detail what I want to accomplish, followed my my code.

Is there a question in there somewhere?

Regards,

Dave

"Question? What's the question?"
--- Larry King on 'Larry King Live'
  #3  
Old 27-Nov-2006, 19:26
mfm1983 mfm1983 is offline
New Member
 
Join Date: Nov 2006
Posts: 5
mfm1983 is on a distinguished road
Smile

Re: Text-Based Roulette Game


Sorry...a good question to help me might be can someone advise me on how I can get my program to flow. I sorta built it already, but I don't know how to flow my program. The biggest problem is I'm more comfortable with very few variables. Transitions and algorithm help with some mathematical logic would do be a lot of good. I'm trying to research on how to get this thing to flow, but I took out the loops, because I made it worse. My code is like this so someone can have an easier time with it. Believe me it was much worse when I tried to insert loops.
  #4  
Old 29-Nov-2006, 10:53
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,148
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Text-Based Roulette Game


Quote:
Originally Posted by mfm1983
can someone advise me on how I can get my program to flow. I sorta built it already, but I don't know how to flow my program

I would suggest visualizing the flow first. You have already written a pretty good discription. Now picture yourself actually entering a real live casino. You approach the cashier's cage to establish an account, then head off for the roulette wheel....

Even though this is a computer game, not a real live casino, isn't the idea to make the user of the programmer feel, somewhat, the casino experience? (Too bad there's no buffet and too bad there aren't hostesses circulating with free drinks for all of us, but you can't have everything, right?) At least you can try to learn to lose with grace and aplomb, right?

Then write the sequence in pseudo-code (a non-computer-language narrative that gives the flow in words). As you write the pseudo code, it may become obvious how to actually structure the program. That is, certain tasks that are similar in nature could be implemented in a function that is called from different places in the main program. You might also realize that the specification of the program might need to be refined or corrected in order to get something that is actually implementable. Well, don't worry about such details until you actually have something to work with.

There are no formal rules for writing pseudo-code, and after a while you might find yourself actually writing stuff that looks more like C than English. That's OK, but the idea is to express what you think the program should do before you actually start writing the program iteslf.

I think it's very important to have the program structure and definition in writing before you start actually writing code.

For example starting at the top:

Code:
1. Print Welcome message 2. Loop Print, "How much would you like to deposit?" Get amount If invalid entry, loop some more End of loop 3. Print, "You have just deposited $amount." 4. Loop Print, "Which wheel?" Get wheelname If invalid entry, loop some more End of loop 5. Print, "You will be using wheelname." 6. Loop Print, "Single bet or a series?" Get betpattern If invalid entry, loop some more End of loop 7. If betpattern is "single spin" then Do single spin routine Else /* (it's multiple spin) */ Loop Print "How many spins?" Get numberofspins If invalid entry, loop some more End of loop Print "You will be betting numberofspins" For i = 0; i < numberofspins; i++ Loop /* this looks a little like C */ Do single spin routine If amountleft == 0 then break out of the "for" loop End if; End of "for" loop End of "else" --- the multiple spin /* this is the end of this play, whether it was single or multiple Print "amount remaining is..." /* the rest of your sequence * It all might be in a big loop where you make a trip * to the ATM machine for more money and then * revisit the cashier * or whatever... * Of course a realistic program wouldn't actually let * you leave until you had lost all of your money. It's * just not human nature to leave a casino when you are * actually ahead. */ End of main program Now below the main program, you can define functions used by your program, for example the routine that is called for a spin of the wheel: . . . /* Note that this allows the bettor to place an amount up to * the amount remaining in his/her account on a single bet * "Real" roulette players often place multiple bets on a given * spin of the wheel. (Some on a number, some on black/red, some * on lines or corners between various spots of the board, etc.) */ Single Spin Routine: Enter with amount in account, return with amount in the account after spinning the wheel 1. Loop Print "You have $amount in your account. How much would like to bet?" Get amountofbet if invalid entry then loop some more End of loop 2. Print the amount you are betting on this spin is $amountofbet 3. Loop Print Where would you like to place the bet? Get wheretoplace if invalid entry then loop some more 4. Your bet is placed on wheretoplace 5. Spin the wheel (random number routine of some sort) 6. Calculate results of bet (if the player won, increase his/her account according to the odds on that play. otherwise decrease his/her account by the amount of the bet 7. Return with newly calculated amount in the account. . . .

How much of this has to do with playing the game and how much with handling user input? How many loops?

Sometimes the program specification is enough to let you start writing code without actually writing a detailed pseudo-code sequence, especially after you have done this a few times (or a few hundred times). But for now, I would suggest that you not try to write the whole program at one time. I can't tell you how frustrating it is to see that someone has written hundreds (thousands?) of lines of code without ever compiling any part of it and then asking, "Why am I getting all of these nasty messages from the compiler?"

I suggest that you do a little at a time. Compile it as you add each little piece. Test it. Yes, Run the program with a very limited amount of code and make absolutely sure that you are handling everything correctly before going on to the next piece. This is especially true of the pieces with user input (whether the programmer has lots and lots of experience or not so much).


So: I suggest that you do steps 1. and 2. in a program all by themselves. You can paste the useful parts of the code that you have already entered, but make a brand new project file for your main() function.

If you are going to deal only with whole numbers (integer numbers of dollars or euros or whatever), then your program variables might be ints. (If you are going to play 21 ---sometimes known as Blackjack--- note that some payoffs are 1.5 to 1, so even if user inputs are always whole numbers, fractional numbers might be encountered unless you store all values internally as cents and not dollars.)

Make a main() function. Create an int variable, say, amount_in_account (or whatever kind of notation that you like to use --- maybe amountInAccount). The point is, don't call it "n" or "x" or some such silly thing. Make the name meaningful. Trust me: it will make a difference some day.

Printing the greeting is trivial, but it has to be done (these things just don't do themselves, you know). Put it there. Compile the program. Execute it. Make sure your compiler is working and that you can run the program. I don't mean to be condescending, and I know that you have already done some programs, but for a new project, do something extremely simple to make sure everything is set up correctly.

Now make the loop to get user input. You are going to insist that the user enter a positive integer, and won't accept anything else. (As you encounter this type of problem a number of times in your program, you might consider making this a function, but for now, don't worry about it. Just do it.)

Now, Stop! Don't even think about doing anything else until you have made sure that this little piece of code works as you think it should. Run the program and give it good input. (A positive integer.) Run it again with bad input: input zero; input a negative integer; input a non-numeric value; enter a fractional number. Get it right and test, test, test. You can't prove a program works by testing, but you should test with everything that you can think of. Not just with good data; that's trivial. Try to think of all of the bad things that you can give the program. Make sure that the program can detect it and handle it. Looking at your program, you are going to do this a number of times. If you test it right now, you can have some confidence that you won't have to worry about its correctness later.

Then, and only then, go to the next step.


Regards,

Dave
  #5  
Old 29-Nov-2006, 11:18
mfm1983 mfm1983 is offline
New Member
 
Join Date: Nov 2006
Posts: 5
mfm1983 is on a distinguished road
Smile

Re: Text-Based Roulette Game


This procedure although involving a great deal more time I think this is exactly what I need until I am more comfortable with writing code off the bat. Unfortunately, I have military duty this weekend and it totally left my mind that I have another program to write for class. I'll try using that method for that program and keep this program on hold until I have enough time to finish it. Thanks so much for taking the time to break it down for me. I think the Deitel Deitel book I bought is a little advanced for me. When I get back to my program which should be in a week or so I'll post something if I have further questions.
  #6  
Old 29-Nov-2006, 12:20
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,148
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Text-Based Roulette Game


Quote:
Originally Posted by mfm1983
I have military duty this weekend


Good luck and, as we old sailors always say, "Keep your powder dry."

Regards,

Dave
 
 

Recent GIDBlogCompress Your Web Site by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with displaying text in game! seabreeze C++ Forum 1 11-Jul-2006 02:02
Text Based RPG Web Hosting AddeloBlack Free Web Hosting 3 19-Mar-2006 15:51
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:28.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.