Read everything before doing anything.
This program plays a simplified version of roulette. You start out with $100.00 (virtual dollars, of course!). The program repeatedly asks you if you wants to bet on Odd, Even, Zero, or Quit. The player may enter O, E, Z, or Q in either uppercase or lowercase. If the player enters an invalid character, you have to give an error message.
If you don’t quit, the program will place a fixed bet of $5 for you and spin the wheel and get a number from 0 to 36 inclusive. If you guessed correctly, you win $5. If you guessed wrong, you lose the $5. The zero is special–it doesn’t count as even or odd, so if you guessed Zero and a zero comes up, you win $50.
After each bet, the program tells you how much money you have left and congratulates you if you win or consoles you if you lost.
If you lose all your money, the program stops; otherwise, it asks for a new bet.
When you decide to quit (or you run out of money), your program will show the number of times you won, the number of times you lost, and the amount of money you have left.
You will save the program in a file whose name is in the form lastname_firstname_roulette.cpp. Thus, if your name is Arthur Fellig, your file should be named fellig_arthur_roulette.cpp. If your file is not named properly, it will not be graded.
Here is information to help you write your program.
Give instructions to the player.
Seed the random number generator.
while (Money Remaining > 0 and Type of Bet is not Quit)
{
Prompt player for Type of Bet
If the Type of Bet is Even or Odd or Zero:
{
Generate a random Wheel Number from 0 to 36 (inclusive)
Display Wheel Number
if (Wheel Number is zero and player chose Zero
OR Wheel Number is odd and player chose Odd
OR Wheel Number is even (but not zero) and player chose Even)
{
if (WheelNumber is zero)
{
Add ZERO_WIN_AMOUNT to Money Remaining
}
else
{
Add BET_AMOUNT to Money Remaining
}
Add one to Number of Wins
Congratulate player and display Money Remaining
}
else
{
Subtract BET_AMOUNT from Money Remaining
Add one to Number of Losses
Tell player “sorry” and display Money Remaining
}
}
else if (Type of Bet is not Q)
{
Print an error message for invalid input
}
}
Print the Money Remaining, Number of Wins, and Number of Losses
Here’s a sample of output from a working program. Player’s input is shown in bold and dark red like this to help you see what the player has entered.
Your output does not have to look exactly like this (though it is well designed), but your output must reflect the same information.
Welcome to roulette. You may bet on Even, Odd, or Zero (use E, O, or Z). Each bet is $5. If you bet on zero and win, you win $50. You can choose Q to quit the game. The game ends automatically if you run out of money. Bet on E)ven, O)dd, Z)ero or Q)uit > e The wheel comes up 25 Sorry, you lose. You now have $95 Bet on E)ven, O)dd, Z)ero or Q)uit > o The wheel comes up 22 Sorry, you lose. You now have $90 Bet on E)ven, O)dd, Z)ero or Q)uit > o The wheel comes up 3 You win! You now have $95 Bet on E)ven, O)dd, Z)ero or Q)uit > z The wheel comes up 5 Sorry, you lose. You now have $90 Bet on E)ven, O)dd, Z)ero or Q)uit > a Please enter E for Even, O for Odd, Z for Zero, or Q to quit. Bet on E)ven, O)dd, Z)ero or Q)uit > E The wheel comes up 15 Sorry, you lose. You now have $85 Bet on E)ven, O)dd, Z)ero or Q)uit > q Your remaining money is $85 Number of wins: 1 Number of losses: 4
Make sure you do your test for “winning” correctly.
Remember that zero is an even number, but it does not win
an “even” bet! This program has if
statements inside of if statements. It will be much easier
for you to handle when you indent correctly. Later on this semester
we’ll find out how to break a large problem into subtasks so that
it doesn’t look so overwhelming.
Attach the .cpp file to an email and send it to the instructor. You must put the words CIT020 C++ Assignment Loops in the subject line of your email, or your program will not be graded.