Question

In: Computer Science

Hello, this is for C#. Initialize variable balance to 1000 dollars. Prompt the player to enter...

Hello, this is for C#. Initialize variable balance to 1000 dollars. Prompt the player to enter a wager. Check that wager is less than or equal to balance, and if it’s not, have the user reenter wager until a valid wager is entered. After a correct wager is entered, run one game of craps. If the player wins, increase balance by wager and display the new balance. If the player loses, decrease balance by wager, display the new balance, check whether balance has become zero and, if so, display the message “Sorry. You busted!”

Solutions

Expert Solution

Hi,

please find the below code which will fulfill your requirement.

using System.IO;
using System;

class Program
{
public static int Balance = 1000;
public bool WagerCheck(int balance,int wager)
{ return wager<= balance;
  
}
static void Main()
{
Program p = new Program();
Console.WriteLine("Enter wager:");// Prompt
loop: string str = Console.ReadLine();
  
  
int value;
if (int.TryParse(str, out value)) // Try to parse the string as an integer
{
if (p.WagerCheck(Balance,value))
{
CRAPGame c = new CRAPGame();
string result =c.Play();
if(result=="win")
{
Console.WriteLine(" you win !!!, balance:"+(Balance+value));
}
else
{Console.WriteLine(" you lost !!!, balance:"+(Balance-value));}
}
  
else
{ Console.WriteLine("Please Enter wager less then or equal to your balance:");
goto loop;
}
}
else
{
Console.WriteLine("Not an integer!");
}

}
}
public class CRAPGame
{
//Creating a random number generator for use in methd RollDice
private Random randomNumber = new Random();
private enum Status //ENUM WITH CONSTATNT THAT REPRESENT GAME STATUS
{
CONTINUE,
WON,
LOST
}
private enum DiceNames
{
SNAKE_EYES = 2,
TREY = 3,
SEVEN = 7,
YO_LEVEN = 11,
BOX_CARS = 12
}
// PLAY ONE GAME OF CRAPGame
public string Play()
{
Status gameStatus = Status.CONTINUE;
int myPoint = 0;
int sumOfDice = RollDice();
switch ((DiceNames)sumOfDice)
{
case DiceNames.SEVEN:
case DiceNames.YO_LEVEN:
gameStatus = Status.WON;
break;
case DiceNames.BOX_CARS:
case DiceNames.SNAKE_EYES:
case DiceNames.TREY:
gameStatus = Status.LOST;
break;
default:
gameStatus= Status.CONTINUE;
myPoint = sumOfDice;
Console.WriteLine("Point is {0}", myPoint);
break;
}
while (gameStatus == Status.CONTINUE)
{
sumOfDice = RollDice(); // roll dice again
if (sumOfDice == myPoint)
gameStatus = Status.WON;
if (sumOfDice == (int)DiceNames.SEVEN)
gameStatus = Status.LOST;
}
// end of while method
// Display won or loss
if (gameStatus == Status.WON)
{Console.WriteLine("Player Wins");
return ("win");}
else
{return ("loss");}
Console.WriteLine("Player Losses");
}//end of method Play
public int RollDice()
{
int die1 = randomNumber.Next(1, 7);
int die2 = randomNumber.Next(1, 7);
int sum = die1 + die2;
//Display result of this roll
Console.WriteLine("Player rolled {0} + {1} = {2}", die1, die2, sum);
return sum;
}// End method roll dice
}


Related Solutions

Hello, this is for C#. Initialize variable balance to 1000 dollars. Prompt the player to enter...
Hello, this is for C#. Initialize variable balance to 1000 dollars. Prompt the player to enter a wager. Check that wager is less than or equal to balance, and if it’s not, have the user reenter wager until a valid wager is entered. After a correct wager is entered, run one game of craps. If the player wins, increase balance by wager and display the new balance. If the player loses, decrease balance by wager, display the new balance, check...
Declare a string variable and initialize it with your first name ( in C++)
Declare a string variable and initialize it with your first name ( in C++)
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter....
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter. You can assume that the the length of this message will be less than 100 characters. You will then parae this message, character by character, converting them to lower case, and find corresponding characters in the words found in the key text word array. Once a character match is found, you will write the index of the word and the index of the character...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the week and display the full name of the day of the week. Use an enumerated data type to solve this problem. Enumerate the days of the week in a data type. Start with Monday and end with Friday. Set all of the characters of the user input to lower case. Set an enumerated value based on the user input. Create a function that displays...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
Create a C# application for Cricket Team that allows you to enter data for player of...
Create a C# application for Cricket Team that allows you to enter data for player of Cricket Team and saves the data to a file named Players.txt. Create a Player class that contains fields for of participant's first name, last name, age, salary and position (wicketkeeper, bawler, striker, midwicket), and To String() method. The fields of records in the file are separated with semicolon (. Expecting sentinel value for ending the process of writing to file is *. E.g. of...
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT