In: Computer Science
Lets make a Deal c# simulation?
The steps that you will need to complete this homework is:
//display and output to the screen telling the player that they can win a car with exactly $1000
//simulate the rolling of the die for $100, $200 or $300
//show the player the amount they have just rolled
//show the player their total amount
//check if total amount has not exceeded $1000. If exceeded, game over (tell player they lost)
//if total is exactly $1000, game over, tell they won a new car!
//ask the player if they want to keep rolling or take the money
//if keep the money, showing output to the screen showing the amount they have won
//if keep rolling, go back to step two
C# PROGRAM:
OUTPUT SNAPSHOTS:
TEXT CODE:
using System;
class HelloWorld {
static void Main() {
// Declaration of variable to store total amount
int totalAmount = 0;
// Declaration of integer array to store die value
int[] dieValue = {100, 200, 300};
/* Displaying and output to the screen telling the player that they
can win a car with exactly $1000 */
Console.WriteLine("You can win a car with exactly $1000\n");
do{
Console.WriteLine("\nPress Enter to Roll the die...");
Console.ReadLine();
/* Simulating the rolling of the die for $100, $200 or $300
*/
Random randObj = new Random(); // Creating object of Random
class
int randValue= randObj.Next(3); // Generating random number between
0 to 2
// Adding the rolled die value to the total amount
totalAmount = totalAmount + dieValue[randValue];
/* Showing the player the amount they have just rolled */
Console.WriteLine("Rolled Dice Value :$" +
dieValue[randValue]);
/* Showing the player their total amount */
Console.WriteLine("Total Amount :$" + totalAmount);
/* Check if total amount has not exceeded $1000. If exceeded, game
over (telling player they lost) */
if(totalAmount>1000){
Console.WriteLine("Ouch.. You Lost, Total Amount exceeded
$1000");
}else if (totalAmount==1000){ /* if total is exactly $1000, game
over, telling they won a new car! */
Console.WriteLine("Congratulations!, You won a new car.");
}
if(totalAmount>=1000){
/* Asking the player if they want to keep rolling or take the money
*/
Console.WriteLine("Do you want to keep the money or Keep
Rolling?");
Console.WriteLine("Enter 1 for Keeping Money");
Console.WriteLine("Enter 2 for Keep Rolling");
// Storing user input in userSelection variable
string userSelection = Console.ReadLine();
/* if keep the money, showing output to the screen showing the
amount they have won */
if(userSelection=="1"){
Console.WriteLine("\nYou won total amount of $"+totalAmount);
break;
} else if(userSelection=="2"){ /* if keep rolling, go back to step
two */
totalAmount = 0;
} else{
Console.WriteLine("\nInvalid Input!");
}
}
}while(totalAmount<1000);
}
}
EXPLANATION: