PROGRAM You are to write a program that will be a simplified version of a craps
ID: 3559688 • Letter: P
Question
PROGRAM
You are to write a program that will be a simplified version of a craps table. For those of you who are unfamiliar with the games of craps, it is a casino game which involves betting on the outcome of the rolling of dice at a so-called craps table. Here is the basic order of play for a single game:
1. The player ("shooter") makes a first roll of a pair of dice. This is called the "come-out roll".
2. Three things can happen depending on the roll:
a. If the come-out roll is 7 or 11, the player wins immediately (a "natural" win).
b. If the come-out roll is 2, 3 or 12, that is called "craps" and the player loses immediately. c. Any other roll becomes the "point", and play continues with step 3 below.
3. The player now must roll the dice again. a. If the point is rolled, the player wins. b. If a 7 is rolled, the player loses.
c. If neither the point nor the 7 are rolled, the player must roll the dice again (going back to step 3), continuing until either a 7 or the point are rolled.
In the Las Vegas version of craps, there are many ways gamblers can bet on the outcome of a game. In your version, you will only allow to types of bets:
1. A "Pass" bet means that you think the shooter will win the game, in one of the ways described above. It doesn't matter if the shooter wins by rolling a 7 or 11 on the come-out, or by rolling the point; both are considered a win, and the bettor will win even money (for example, ifthe bet is $10, the bettor gets back the $10 that were bet plus an additional $10 from "the house").
2. A "Don't Pass" bet means that you think the shooter will lose the game. Again, it doesn't matter how the shooter loses- he can roll craps on the come-out roll, or roll a 7 before he rolls his point. Either way, a shooter's loss results in a Don't Pass bet winning. The bettor receives even money for a wirming bet.
In your program, you will ask for the user's name and how much money he (or she!) has to start off with in his "account". The user will then place a bet before starting a game of craps; he will have to select Pass or Don't Pass, and wager a specific amount of money. The player's account will grow or diminish depending on how much he has bet and whether he wins or loses. The player can keep playing games until he chooses to quit or until he loses all his money.
The use of functions for this program is not required, but it is encouraged.
SAMPLE SESSION
Here is what your programay look like when you run it. (Program output is in regular text, user input is in bold).
Let's Play Craps!
This program simulates a session at a craps table!
What's your first name, slick? Elvis
How much money do you have? 1000
(continued)
Round 1
Bet on Pass or Don't Pass? P How much do you wager? 10000
Error1 enter a smaller amount.
Don't let the user bet more than he has in his account!
How much do you wager? 100
Enter R to roll: R Roll is 4
4 is the point! Enter R to roll: R
Roll is 5 Enter R to roll: R Roll is 8 Enter R to roll: R Roll is 4
Shooter wins!
You win!
Your balance is $1100
Play again (y/n)? y Play continues until the user chooses not to play again or until the user hits $0.
Round 2
Bet on Pass or Don't Pass? D How much do you wager? 100
Enter R to roll: R Roll is 2
Craps!
Shooter loses!
You win!
Your balance is $1200
Play again (y/n)? n
Elvis has left the building!
Explanation / Answer
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
string username = "";
float balance = 0.0;
float wageramt = 0.0;
int round = 0;
int roll, point;
char bet;
char ans;
char input;
cout << "Let's Play Craps!" << endl;
cout << "This program simulates a session at a craps table!" << endl << endl;
cout << "What's your first name, slick? " ;
cin >> username;
cout << "How much money do you have? ";
cin >> balance;
do{
round++;
cout << "Round " << round << endl;
cout << "Bet on Pass or Don't Pass? ";
cin >> bet;
if(bet == 'P'){
cout << "How much do you wager? ";
cin >> wageramt;
if(wageramt <= balance){
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
cout << "Roll is " << roll << endl;
if(roll == 7 || roll == 11){
cout << "Shooter wins!" << endl;
cout << "You win!" << endl;
cout << "Your balance is $" << (balance + wageramt) << endl;
balance+=wageramt;
}else if(roll == 2 || roll == 3 || roll == 12){
cout << "Shooter looses!" << endl;
cout << "You lose." << endl;
cout << "Your balance is $" << (balance - wageramt) << endl;
balance-=wageramt;
}else{
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
point = roll;
cout << "Point is " << point << "!" << endl;
while(1){
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
cout << "Roll is " << roll << endl;
if(roll == 7){
cout << "Shooter looses!" << endl;
cout << "You lose." << endl;
cout << "Your balance is $" << (balance - wageramt) << endl;
balance-=wageramt;
break;
}else if(roll == point){
cout << "Shooter wins!" << endl;
cout << "You win!" << endl;
cout << "Your balance is $" << (balance + wageramt) << endl;
balance+=wageramt;
break;
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}else{
cout << "Error1 : Enter a smaller amount." << endl;
}
}
if(bet == 'D'){
cout << "How much do you wager? ";
cin >> wageramt;
if(wageramt <= balance){
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
cout << "Roll is " << roll << endl;
if(roll == 7 || roll == 11){
cout << "Shooter wins!" << endl;
cout << "You lose." << endl;
cout << "Your balance is $" << (balance - wageramt) << endl;
balance-=wageramt;
}else if(roll == 2 || roll == 3 || roll == 12){
cout << "Shooter looses!" << endl;
cout << "You win!" << endl;
cout << "Your balance is $" << (balance + wageramt) << endl;
balance+=wageramt;
}else{
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
point = roll;
cout << "Point is " << point << "!" << endl;
while(1){
cout << "Enter R to roll: ";
cin >> input;
if(input == 'R'){
roll = rand()%12+1;
cout << "Roll is " << roll << endl;
if(roll == 7){
cout << "Shooter looses!" << endl;
cout << "You win!" << endl;
cout << "Your balance is $" << (balance + wageramt) << endl;
balance+=wageramt;
break;
}else if(roll == point){
cout << "Shooter wins!" << endl;
cout << "You loose!" << endl;
cout << "Your balance is $" << (balance - wageramt) << endl;
balance-=wageramt;
break;
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}
}else{
while(input != 'R'){
cout << "Enter R to roll: " << endl;
}
}
}else{
cout << "Error1 : Enter a smaller amount." << endl;
}
}
cout << "Play again (y/n)? ";
cin >> ans;
}while((ans == 'y' || ans == 'Y') && (balance > 0) );
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.