Modify the craps program to allow wagering inside of C#. Initialize variable Balance to 1000 dollars. Prompt the player to enter a wager. Check whether the wager is less than or equal to Balance and, if not, have the user reenter the wager until a valid wager is entered. After a valid wager is entered, run one game of craps. If the player wins, increase Balance by wager, and print the new Balance. If the player loses, decrease Balance by wager, print the new Balance, check whether Balance has become zero and, if so, print the message “Sorry. You busted!” (explain steps as much as possible so I can understand plz). The program to modify has the code listed below: // Craps class simulates

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Modify the craps program to allow wagering inside of C#. Initialize variable Balance to 1000 dollars. Prompt the player to enter a wager. Check whether the wager is less than or equal to Balance and, if not, have the user reenter the wager until a valid wager is entered. After a valid wager is entered, run one game of craps. If the player wins, increase Balance by wager, and print the new Balance. If the player loses, decrease Balance by wager, print the new Balance, check whether Balance has become zero and, if so, print the message “Sorry. You busted!” (explain steps as much as possible so I can understand plz).

The program to modify has the code listed below:

// Craps class simulates the dice game craps.
using System;

class Craps
{
// create random-number generator for use in method RollDice
private static Random randomNumbers = new Random();

// enumeration with constants that represent the game status
private enum Status {Continue, Won, Lost}

// enumeration with constants that represent common rolls of the dice
private enum DiceNames
{
SnakeEyes = 2,
Trey = 3,
Seven = 7,
YoLeven = 11,
BoxCars = 12
}

// plays one game of craps
static void Main()
{
// gameStatus can contain Continue, Won or Lost
Status gameStatus = Status.Continue;
int myPoint = 0; // point if no win or loss on first roll

int sumOfDice = RollDice(); // first roll of the dice

// determine game status and point based on first roll
switch ((DiceNames)sumOfDice)
{
case DiceNames.Seven: // win with 7 on first roll
case DiceNames.YoLeven: // win with 11 on first roll
gameStatus = Status.Won;
break;
case DiceNames.SnakeEyes: // lose with 2 on first roll
case DiceNames.Trey: // lose with 3 on first roll
case DiceNames.BoxCars: // lose with 12 on first roll
gameStatus = Status.Lost;
break;
default: // did not win or lose, so remember point
gameStatus = Status.Continue; // game is not over
myPoint = sumOfDice; // remember the point
Console.WriteLine($"Point is {myPoint}");
break;
}

// while game is not complete
while (gameStatus == Status.Continue) // game not Won or Lost
{
sumOfDice = RollDice(); // roll dice again

// determine game status
if (sumOfDice == myPoint) // win by making point
{
gameStatus = Status.Won;
}
else
{
// lose by rolling 7 before point
if (sumOfDice == (int)DiceNames.Seven)
{
gameStatus = Status.Lost;
}
}
}

// display won or lost message
if (gameStatus == Status.Won)
{
Console.WriteLine("Player wins");
}
else
{
Console.WriteLine("Player loses");
}
}

// roll dice, calculate sum and display results
static int RollDice()
{
// pick random die values
int die1 = randomNumbers.Next(1, 7); // first die roll
int die2 = randomNumbers.Next(1, 7); // second die roll

int sum = die1 + die2; // sum of die values

// display results of this roll
Console.WriteLine($"Player rolled {die1} + {die2} = {sum}");
return sum; // return sum of dice
}
}

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education