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

#include <iostream>

#include <cstdlib>

srand and rand

#include <ctime>

using std::cout;

using std::endl;

using std::cin;

enum Status { CONTINUE, WON, LOST };

int rollDice( void ); // function prototype

void playGame ( Status & gameStatus );

void displayWonOrLost ( Status, int &, int & );

int main()

{

int BankBalance = 1000;

int Wager;

char Response;

Status gameStatus;

cout << "Please enter a wager (You start with 1000 USD!)" << endl;

cin >> Wager;

while ( Wager <= BankBalance )

{

cout << "Continue with current wager (Y), enter a new wager (E) or

end game (N)?" << endl;

cin >> Response;

switch ( Response ) {

case 'Y':

case 'y':

playGame( gameStatus );

displayWonOrLost ( gameStatus, BankBalance, Wager );

break;

case 'N':

case 'n':

cout << "Your final balance is " << BankBalance << endl;

cout << "Thank you, come again!" << endl;

return 0;

break;

case 'E':

case 'e':

cout << "Please enter the new wager!" << endl;

cin >> Wager;

break;

default:

cout << "Incorrect Response. Please try again!" << endl;

break;

}

}

/*if ( Wager > BankBalance )

{

cout << "Re-enter wager!" << endl;

cin >> Wager;

}

if ( BankBalance == 0 )

cout << "Sorry, you busted!" << endl;

return 0;

}

void displayWonOrLost ( Status gameStatus, int & passedBalance, int &

passedWager )

{

if ( gameStatus == WON ) {

passedBalance += passedWager;

cout << "Player wins, new balance is " << passedBalance << endl;

cout << "You are awesome! Keep Going!" << endl;

}

else {

passedBalance -= passedWager;

cout << "Player loses, new balance is " << passedBalance << endl;

cout << "You suck! Get out while you can!" << endl;

}

}

void playGame (Status & gameStatus)

{

int sum;

int myPoint;

srand( time( 0 ) );

sum = rollDice();

switch ( sum )

{

case 7:

case 11:

gameStatus = WON;

break;

case 2:

case 3:

case 12:

gameStatus = LOST;

break;

default:

gameStatus = CONTINUE;

myPoint = sum;

cout << "Point is " << myPoint << endl;

break;

}

while ( gameStatus == CONTINUE )

{

sum = rollDice();

if ( sum == myPoint )

gameStatus = WON;

else

if ( sum == 7 )

gameStatus = LOST;

}

}

int rollDice( void )

{

int die1;

int die2;

int workSum;

die1 = 1 + rand() % 6;

die2 = 1 + rand() % 6;

workSum = die1 + die2;

cout << "Player rolled " << die1 << " + " << die2

<< " = " << workSum << endl;

return workSum;

}


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