Modify the craps program to allow wagering inside of C#, and explain each step (reject if you can't). 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).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Modify the craps program to allow wagering inside of C#, and explain each step (reject if you can't). 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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 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-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY